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;
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations