Add mapsquare key for compatibility with Polar's XTEA key files

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent 5cfb234cc7
commit cbeb9a3a67
  1. 17
      archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt

@ -1,5 +1,6 @@
package org.openrs2.archive.cache package org.openrs2.archive.cache
import com.fasterxml.jackson.annotation.JsonProperty
import io.netty.buffer.ByteBufAllocator import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.Unpooled import io.netty.buffer.Unpooled
import org.openrs2.buffer.use import org.openrs2.buffer.use
@ -30,6 +31,7 @@ public class CacheExporter @Inject constructor(
val group: Int, val group: Int,
val nameHash: Int?, val nameHash: Int?,
val name: String?, val name: String?,
@JsonProperty("mapsquare") val mapSquare: Int?,
val key: XteaKey val key: XteaKey
) )
@ -166,7 +168,8 @@ public class CacheExporter @Inject constructor(
val k2 = rows.getInt(7) val k2 = rows.getInt(7)
val k3 = rows.getInt(8) val k3 = rows.getInt(8)
keys += GroupKey(archive, group, nameHash, name, XteaKey(k0, k1, k2, k3)) val mapSquare = getMapSquare(name)
keys += GroupKey(archive, group, nameHash, name, mapSquare, XteaKey(k0, k1, k2, k3))
} }
keys keys
@ -177,5 +180,17 @@ public class CacheExporter @Inject constructor(
private companion object { private companion object {
private const val BATCH_SIZE = 1024 private const val BATCH_SIZE = 1024
private val LOC_NAME_REGEX = Regex("l(\\d+)_(\\d+)")
private fun getMapSquare(name: String?): Int? {
if (name == null) {
return null
}
val match = LOC_NAME_REGEX.matchEntire(name) ?: return null
val x = match.groupValues[1].toInt()
val z = match.groupValues[2].toInt()
return (x shl 8) or z
}
} }
} }

Loading…
Cancel
Save