Add support for the new OSRS short code map format

Signed-off-by: Graham <gpe@openrs2.org>
Graham 2 years ago
parent 2c70a7c1ec
commit 2d7b235f15
  1. 44
      archive/src/main/kotlin/org/openrs2/archive/map/MapRenderer.kt

@ -344,6 +344,40 @@ public class MapRenderer @Inject constructor(
} }
} }
private fun isShortCode(buf: ByteBuf): Boolean {
for (plane in 0 until LEVELS) {
for (dx in 0 until MAP_SIZE) {
for (dz in 0 until MAP_SIZE) {
while (true) {
if (buf.readableBytes() < 2) {
return false
}
val code = buf.readUnsignedShort()
if (code == 0) {
break
} else if (code == 1) {
if (!buf.isReadable) {
return false
}
buf.skipBytes(1)
break
} else if (code <= 49) {
if (buf.readableBytes() < 2) {
return false
}
buf.skipBytes(2)
}
}
}
}
}
return !buf.isReadable
}
private fun renderMap( private fun renderMap(
image: BufferedImage, image: BufferedImage,
x: Int, x: Int,
@ -352,6 +386,12 @@ public class MapRenderer @Inject constructor(
underlayColors: Map<Int, Int>, underlayColors: Map<Int, Int>,
overlayColors: Map<Int, Int> overlayColors: Map<Int, Int>
) { ) {
val readCode = if (isShortCode(buf.slice())) {
buf::readUnsignedShort
} else {
{ buf.readUnsignedByte().toInt() }
}
for (plane in 0 until LEVELS) { for (plane in 0 until LEVELS) {
for (dx in 0 until MAP_SIZE) { for (dx in 0 until MAP_SIZE) {
for (dz in 0 until MAP_SIZE) { for (dz in 0 until MAP_SIZE) {
@ -360,14 +400,14 @@ public class MapRenderer @Inject constructor(
var underlay = 0 var underlay = 0
while (true) { while (true) {
val code = buf.readUnsignedByte().toInt() val code = readCode()
if (code == 0) { if (code == 0) {
break break
} else if (code == 1) { } else if (code == 1) {
buf.skipBytes(1) buf.skipBytes(1)
break break
} else if (code <= 49) { } else if (code <= 49) {
overlay = buf.readUnsignedByte().toInt() overlay = readCode()
shape = (code - 2) shr 2 shape = (code - 2) shr 2
} else if (code <= 81) { } else if (code <= 81) {
// empty // empty

Loading…
Cancel
Save