Search in sources :

Example 1 with Archive

use of org.apollo.cache.archive.Archive in project apollo by apollo-rsps.

the class IndexedFileSystem method getArchive.

/**
 * Gets the {@link Archive} pointed to by the specified {@link FileDescriptor}.
 *
 * @param type The file type.
 * @param file The file id.
 * @return The Archive.
 * @throws IOException If there is an error decoding the Archive.
 */
public Archive getArchive(int type, int file) throws IOException {
    FileDescriptor descriptor = new FileDescriptor(type, file);
    Archive cached = cache.get(descriptor);
    if (cached == null) {
        cached = Archive.decode(getFile(descriptor));
        synchronized (this) {
            cache.put(descriptor, cached);
        }
    }
    return cached;
}
Also used : Archive(org.apollo.cache.archive.Archive)

Example 2 with Archive

use of org.apollo.cache.archive.Archive in project apollo by apollo-rsps.

the class ItemDefinitionDecoder method run.

@Override
public void run() {
    try {
        Archive config = fs.getArchive(0, 2);
        ByteBuffer data = config.getEntry("obj.dat").getBuffer();
        ByteBuffer idx = config.getEntry("obj.idx").getBuffer();
        int count = idx.getShort(), index = 2;
        int[] indices = new int[count];
        for (int i = 0; i < count; i++) {
            indices[i] = index;
            index += idx.getShort();
        }
        ItemDefinition[] definitions = new ItemDefinition[count];
        for (int i = 0; i < count; i++) {
            data.position(indices[i]);
            definitions[i] = decode(i, data);
        }
        ItemDefinition.init(definitions);
    } catch (IOException e) {
        throw new UncheckedIOException("Error decoding ItemDefinitions.", e);
    }
}
Also used : Archive(org.apollo.cache.archive.Archive) ItemDefinition(org.apollo.cache.def.ItemDefinition) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 3 with Archive

use of org.apollo.cache.archive.Archive in project apollo by apollo-rsps.

the class ObjectDefinitionDecoder method run.

@Override
public void run() {
    try {
        Archive config = fs.getArchive(0, 2);
        ByteBuffer data = config.getEntry("loc.dat").getBuffer();
        ByteBuffer idx = config.getEntry("loc.idx").getBuffer();
        int count = idx.getShort(), index = 2;
        int[] indices = new int[count];
        for (int i = 0; i < count; i++) {
            indices[i] = index;
            index += idx.getShort();
        }
        ObjectDefinition[] definitions = new ObjectDefinition[count];
        for (int i = 0; i < count; i++) {
            data.position(indices[i]);
            definitions[i] = decode(i, data);
        }
        ObjectDefinition.init(definitions);
    } catch (IOException e) {
        throw new UncheckedIOException("Error decoding ObjectDefinitions.", e);
    }
}
Also used : Archive(org.apollo.cache.archive.Archive) ObjectDefinition(org.apollo.cache.def.ObjectDefinition) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 4 with Archive

use of org.apollo.cache.archive.Archive in project apollo by apollo-rsps.

the class MapIndexDecoder method decode.

/**
 * Decodes {@link MapIndex}s from the specified {@link IndexedFileSystem}.
 *
 * @return A {@link Map} of packed coordinates to their MapDefinitions.
 * @throws IOException If there is an error reading or decoding the Archive.
 */
public Map<Integer, MapIndex> decode() throws IOException {
    Archive archive = fs.getArchive(0, VERSIONS_ARCHIVE_FILE_ID);
    ArchiveEntry entry = archive.getEntry("map_index");
    Map<Integer, MapIndex> definitions = new HashMap<>();
    ByteBuffer buffer = entry.getBuffer();
    int count = buffer.capacity() / (3 * Short.BYTES + Byte.BYTES);
    for (int times = 0; times < count; times++) {
        int id = buffer.getShort() & 0xFFFF;
        int terrain = buffer.getShort() & 0xFFFF;
        int objects = buffer.getShort() & 0xFFFF;
        boolean members = buffer.get() == 1;
        definitions.put(id, new MapIndex(id, terrain, objects, members));
    }
    return definitions;
}
Also used : Archive(org.apollo.cache.archive.Archive) HashMap(java.util.HashMap) ArchiveEntry(org.apollo.cache.archive.ArchiveEntry) MapIndex(org.apollo.cache.map.MapIndex) ByteBuffer(java.nio.ByteBuffer)

Example 5 with Archive

use of org.apollo.cache.archive.Archive in project apollo by apollo-rsps.

the class NpcDefinitionDecoder method run.

@Override
public void run() {
    try {
        Archive config = fs.getArchive(0, 2);
        ByteBuffer data = config.getEntry("npc.dat").getBuffer();
        ByteBuffer idx = config.getEntry("npc.idx").getBuffer();
        int count = idx.getShort(), index = 2;
        int[] indices = new int[count];
        for (int i = 0; i < count; i++) {
            indices[i] = index;
            index += idx.getShort();
        }
        NpcDefinition[] definitions = new NpcDefinition[count];
        for (int i = 0; i < count; i++) {
            data.position(indices[i]);
            definitions[i] = decode(i, data);
        }
        NpcDefinition.init(definitions);
    } catch (IOException e) {
        throw new UncheckedIOException("Error decoding NpcDefinitions.", e);
    }
}
Also used : Archive(org.apollo.cache.archive.Archive) NpcDefinition(org.apollo.cache.def.NpcDefinition) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Archive (org.apollo.cache.archive.Archive)5 ByteBuffer (java.nio.ByteBuffer)4 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 HashMap (java.util.HashMap)1 ArchiveEntry (org.apollo.cache.archive.ArchiveEntry)1 ItemDefinition (org.apollo.cache.def.ItemDefinition)1 NpcDefinition (org.apollo.cache.def.NpcDefinition)1 ObjectDefinition (org.apollo.cache.def.ObjectDefinition)1 MapIndex (org.apollo.cache.map.MapIndex)1