1package com.runehive.fs.cache.decoder;
3import com.runehive.fs.cache.Cache;
4import com.runehive.fs.cache.FileSystem;
5import com.runehive.fs.util.ByteBufferUtil;
6import com.runehive.fs.util.CompressionUtil;
7import com.runehive.game.world.World;
8import com.runehive.game.world.object.*;
9import com.runehive.game.world.pathfinding.TraversalMap;
10import com.runehive.game.world.position.Position;
11import com.runehive.game.world.region.Region;
12import com.runehive.game.world.region.RegionDefinition;
13import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
14import it.unimi.dsi.fastutil.ints.IntSet;
15import org.apache.logging.log4j.LogManager;
16import org.apache.logging.log4j.Logger;
18import java.nio.ByteBuffer;
19import java.util.Optional;
20import java.util.concurrent.atomic.AtomicInteger;
41 private final AtomicInteger
decoded =
new AtomicInteger();
46 private final AtomicInteger
errors =
new AtomicInteger();
59 LOGGER.info(
"Loading regional map data.");
63 .forEach(def ->
load(mapIndex, def));
68 final int hash = def.getHash();
69 final int x = (hash >> 8 & 0xFF) << 6;
70 final int y = (hash & 0xFF) << 6;
74 ByteBuffer terrainData = mapIndex.
get(def.getTerrainFile());
75 if (terrainData ==
null) {
81 final IntSet downHeights =
new IntOpenHashSet();
85 ByteBuffer gameObjectData = mapIndex.
get(def.getObjectFile());
86 if (gameObjectData ==
null) {
94 }
catch (Exception e) {
111 if (objIdOffset == 0)
break;
113 objId += objIdOffset;
118 if (objPosInfoOffset == 0)
break;
119 objPosInfo += objPosInfoOffset - 1;
121 int objOtherInfo = buf.get() & 0xFF;
122 int localY = objPosInfo & 0x3f;
123 int localX = objPosInfo >> 6 & 0x3f;
124 int height = objPosInfo >> 12 & 0x3;
129 if (downHeights.contains(
Position.
hash(localX, localY, 1))) {
130 if (--height < 0)
continue;
131 }
else if (downHeights.contains(
Position.
hash(localX, localY, height))) {
135 if (!type.isPresent() || !face.isPresent()) {
148 region.skip(staticObject);
162 int[][][] attributes =
new int[4][64][64];
164 for (
int height = 0; height < 4; height++) {
165 for (
int localX = 0; localX < 64; localX++) {
166 for (
int localY = 0; localY < 64; localY++) {
168 int attributeId = mapBuffer.getShort() & 0xFFFF;
169 if (attributeId == 0) {
172 if (attributeId == 1) {
173 int tileHeight = mapBuffer.get() & 0xFF;
176 if (attributeId <= 49) {
177 int overlayId = mapBuffer.getShort() & 0xFFFF;
178 }
else if (attributeId <= 81) {
179 attributes[height][localX][localY] = attributeId - 49;
186 for (
int height = 0; height < 4; height++) {
187 for (
int localX = 0; localX < 64; localX++) {
188 for (
int localY = 0; localY < 64; localY++) {
190 if ((attributes[height][localX][localY] & 2) == 2) {
194 if ((attributes[height][localX][localY] & 1) == 1) {
197 if ((attributes[1][localX][localY] & 2) == 2) {
Represents a Sector and Index cache.
ByteBuffer get(final int indexId)
Gets a ByteBuffer of data within this cache for the specified index id.
Represents a file system of Caches and Archives.
static final int MAP_INDEX
Represents the id of the tool.mapviewer and landscape cache.
final FileSystem fs
The FileSystem.
RegionDecoder(FileSystem fs)
Creates the ObjectDefinitionDecoder.
void load(final Cache mapIndex, final RegionDefinition def)
final AtomicInteger errors
Amount of regions incorrectly decoded.
void parseTerrain(Region region, ByteBuffer mapBuffer, IntSet downHeights)
Loads all of the tool.mapviewer indexes entries and decodes each.
void parseGameObject(Region region, ByteBuffer buf, int x, int y, IntSet downHeights)
Parses a GameObject on the specified coordinates.
static final Logger LOGGER
final AtomicInteger decoded
Amount of regions correctly decoded.
A static-utility class containing extension or helper methods for ByteBuffers.
static int getSmart(final ByteBuffer buffer)
Reads a 'smart' (either a byte or short depending on the value) from the specified buffer.
A static-utility class containing containing extension or helper methods for compressor-deccompressor...
static byte[] gunzip(byte[] data)
Uncompresses a byte array of g-zipped data.
Represents the game world.
static RegionManager getRegions()
Represents a single type of object.
static GameObjectDefinition forId(int id)
Gets an object definition by its id.
Represents a static game object loaded from the map fs.
Contains traversal data for a set of regions.
static void block(Region region, int height, int localX, int localY)
Marks the specified set of coordinates blocked, unable to be passed through.
static void markObject(Region region, GameObject object, boolean add, boolean list)
Marks a GameObject with the specified attributes on the specified Position to the TraversalMap.
Represents a single tile on the game world.
static int hash(int x, int y, int z)
Represents a single region definition.
static Int2ObjectMap< RegionDefinition > getDefinitions()
Gets the regional definitions.
Represents a single region.
static final Set< Position > SKIPPED_OBJECTS
Region getRegion(Position position)
Gets a region by position.
The enumerated type whose elements represent the directions for objects.
static Optional< ObjectDirection > valueOf(final int id)
Returns a ObjectDirection wrapped in an Optional for the specified id.
The enumerated type whose elements represent all of the object types.
static Optional< ObjectType > valueOf(final int id)
Returns a ObjectType wrapped in an Optional for the specified id.