mirror of
https://gitlab.com/2009scape/tools/2009scape-map-viewer.git
synced 2026-08-01 14:39:25 -06:00
Added rest of the decoders + cache lib. Added npc spawn parser for the "nx_y" archive
This commit is contained in:
parent
c83268feab
commit
c75fa8e8c9
13 changed files with 86 additions and 182 deletions
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
import cacheops.cache.definition.data.MapTile
|
||||
import cacheops.cache.definition.data.UnderlayDefinition
|
||||
import cacheops.cache.definition.decoder.FloorUnderlayConfiguration
|
||||
import cacheops.cache.definition.decoder.MapTileParser
|
||||
import cacheops.cache.definition.encoder.MapTileWriter
|
||||
import com.displee.cache.CacheLibrary
|
||||
import com.formdev.flatlaf.FlatDarculaLaf
|
||||
import decoders.FloorUnderlayConfiguration
|
||||
import decoders.MapTileParser
|
||||
import definitions.UnderlayDefinition
|
||||
import encoder.MapTileWriter
|
||||
import world.MapTile
|
||||
import java.awt.*
|
||||
import java.awt.event.KeyEvent
|
||||
import java.awt.event.MouseAdapter
|
||||
|
|
@ -143,7 +143,7 @@ object Rs2MapEditor {
|
|||
defaultBackground = underlayMap[selectedUnderlayId]?.getRGB()!!
|
||||
background = underlayMap[selectedUnderlayId]?.getRGB()
|
||||
|
||||
// Update map tile definitions with new tile information
|
||||
// Update map tile cacheops.definitions with new tile information
|
||||
MapTileParser.definition.setTile(point.x, point.y, 0, MapTile(originalTile.height, originalTile.attrOpcode, originalTile.overlayId, originalTile.overlayPath, originalTile.overlayRotation, originalTile.settings, underlayID))
|
||||
}
|
||||
} else if (SwingUtilities.isRightMouseButton(e)) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package definitions
|
||||
package cacheops.cache.definition.data
|
||||
|
||||
import java.awt.Color
|
||||
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package decoders
|
||||
package cacheops.cache.definition.decoder
|
||||
|
||||
import Rs2MapEditor
|
||||
import cacheops.cache.definition.data.UnderlayDefinition
|
||||
import const.Archives
|
||||
import const.Indices
|
||||
import definitions.UnderlayDefinition
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
object FloorUnderlayConfiguration {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package decoders
|
||||
package cacheops.cache.definition.decoder
|
||||
|
||||
import definitions.UnderlayDefinition
|
||||
import cacheops.cache.definition.data.UnderlayDefinition
|
||||
import ext.medium
|
||||
import ext.unsignedByte
|
||||
import ext.unsignedShort
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package decoders
|
||||
package cacheops.cache.definition.decoder
|
||||
|
||||
import definitions.MapDefinition
|
||||
import cacheops.cache.definition.data.MapDefinition
|
||||
import cacheops.cache.definition.data.MapTile
|
||||
import ext.unsignedByte
|
||||
import world.MapTile
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
class MapTileDecoder {
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package decoders
|
||||
package cacheops.cache.definition.decoder
|
||||
|
||||
import Rs2MapEditor
|
||||
import definitions.MapDefinition
|
||||
import cacheops.cache.definition.data.MapDefinition
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
object MapTileParser {
|
||||
|
|
@ -36,8 +36,6 @@ object MapTileParser {
|
|||
val y = region and 0xFF
|
||||
val mapData = Rs2MapEditor.library.data(5,"m${x}_${y}")
|
||||
|
||||
println("Parsing data size: ${mapData!!.size}")
|
||||
println(mapData.contentToString())
|
||||
MapTileDecoder().readLoop(definition, ByteBuffer.wrap(mapData))
|
||||
}
|
||||
|
||||
42
src/main/kotlin/cacheops/cache/definition/decoder/NPCSpawnDecoder.kt
vendored
Normal file
42
src/main/kotlin/cacheops/cache/definition/decoder/NPCSpawnDecoder.kt
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package cacheops.cache.definition.decoder
|
||||
|
||||
import Rs2MapEditor
|
||||
import ext.unsignedShort
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
class NPCSpawnDecoder {
|
||||
|
||||
fun decode(data: ByteArray) {
|
||||
|
||||
val buffer = ByteBuffer.wrap(data)
|
||||
|
||||
while (buffer.hasRemaining()) {
|
||||
val coords = buffer.unsignedShort()
|
||||
|
||||
val lz = coords shr 14
|
||||
val ly = (coords shr 7) and 0x3f
|
||||
val lx = coords and 0x3f
|
||||
|
||||
val npcID = buffer.unsignedShort()
|
||||
println("Npc: $npcID | Spawn: [$lx, $ly, $lz]")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object NPCSpawnParser {
|
||||
|
||||
fun parseNPCSpawns() {
|
||||
// Meh 18000 is good enough for now and covers all of our regions
|
||||
for (regionIDs in 0..18000) {
|
||||
val x = (regionIDs shr 8) and 0xFF
|
||||
val y = regionIDs and 0xFF
|
||||
val npcSpawnData = Rs2MapEditor.library.data(5, "n${x}_${y}")
|
||||
|
||||
if (npcSpawnData != null && npcSpawnData.isNotEmpty()) {
|
||||
println("NPC DATA FOR $regionIDs")
|
||||
NPCSpawnDecoder().decode(npcSpawnData)
|
||||
println("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package encoder
|
||||
package cacheops.cache.definition.encoder
|
||||
|
||||
import definitions.MapDefinition
|
||||
import cacheops.cache.definition.data.MapDefinition
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
class MapTileEncoder {
|
||||
26
src/main/kotlin/cacheops/cache/definition/encoder/MapTileWriter.kt
vendored
Normal file
26
src/main/kotlin/cacheops/cache/definition/encoder/MapTileWriter.kt
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package cacheops.cache.definition.encoder
|
||||
|
||||
import Rs2MapEditor
|
||||
|
||||
object MapTileWriter {
|
||||
|
||||
fun replaceValues() {
|
||||
val region = Rs2MapEditor.region
|
||||
val baseX = ((region shr 8) shl 6)
|
||||
val baseY = ((region and 0xFF) shl 6)
|
||||
val x = (region shr 8) and 0xFF
|
||||
val y = region and 0xFF
|
||||
|
||||
//TODO: PACK ATMOSPHERE DATA ON THE END!! THE UNDERLAY DECODER ON THE CLIENT NEEDS THE ATMOSPHERE DATA
|
||||
|
||||
// val data = MapTileEncoder().write(MapTileParser.definition)
|
||||
|
||||
// if (data != null || dataSize < 50000) {
|
||||
// Rs2MapEditor.library.put(Indices.LANDSCAPES, "m${x}_${y}", mergedData)
|
||||
// Rs2MapEditor.library.update()
|
||||
// } else {
|
||||
// System.err.println("Something went VERY wrong!")
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package definitions
|
||||
|
||||
import world.MapObject
|
||||
import world.MapTile
|
||||
|
||||
data class MapDefinition(
|
||||
var id: Int = -1,
|
||||
val tiles: MutableMap<Int, MapTile> = mutableMapOf(),
|
||||
val objects: MutableList<MapObject> = mutableListOf()
|
||||
) {
|
||||
|
||||
fun getTile(localX: Int, localY: Int, plane: Int) = tiles[getHash(localX, localY, plane)] ?: MapTile.EMPTY
|
||||
|
||||
fun setTile(localX: Int, localY: Int, plane: Int, tile: MapTile) {
|
||||
tiles[getHash(localX, localY, plane)] = tile
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getHash(localX: Int, localY: Int, plane: Int): Int {
|
||||
return localY + (localX shl 6) + (plane shl 12)
|
||||
}
|
||||
fun getLocalX(tile: Int) = tile shr 6 and 0x3f
|
||||
fun getLocalY(tile: Int) = tile and 0x3f
|
||||
fun getPlane(tile: Int) = tile shr 12 and 0x3
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package encoder
|
||||
|
||||
import Rs2MapEditor
|
||||
import const.Indices
|
||||
import decoders.MapTileParser
|
||||
|
||||
object MapTileWriter {
|
||||
|
||||
val endData = byteArrayOf(0, -128, 2, -86, 2, -85, 2, -84, 2, -83, 2, -82, 2, -81, 1, 56, 0, 2, -42, 12, -63, 0, -36, 1, 1, 2, 1, 2, 1, 2, 23, -112, 6, 0, 2, -42, 9, -63, 0, -36, 1, 1, 2, 1, 2, 1, 2, 23, -112, 70, 0, 6, 67, 9, 63, 0, -36, 1, 0, 0, 1, 1, 2, 1, 23, -112, 102, 0, 6, 64, 12, -64, 0, -36, 1, 0, 2, 0, 2, 0, 2, 23, -112, -58, 0, 2, -13, 11, 64, 0, 61, 1, 1, 2, 1, 2, 1, 2, 23, -94, -58, 1, 7, -35, 20, 102, 0, -56, 1, 0, 0, 1, 2, 1, 2, 23, -112, 8, 0, 3, -69, 6, 85, 0, -36, 1, 0, 0, 0, 3, 0, 3, 23, -112, -58, 0, 15, 34, 8, 34, 0, -44, 1, 0, 2, 0, 2, 0, 0, 23, -112, -90, 0, 15, 13, 6, 117, 0, -44, 1, 0, 0, 0, 2, 0, 2, 23, -112, 6, 0, 22, -63, 23, 1, 0, 33, 0, 0, 1, 23, -94, -95, 0, 22, -71, 23, 52, 0, 68, 1, 0, 3, 1, 2, 0, 3, 23, -94, -26, 0, 24, 73, 23, -64, 0, -44, 1, 0, 2, 0, 2, 0, 2, 23, -112, 6, 0, 24, 73, 22, -65, 0, -44, 1, 0, 2, 0, 2, 0, 2, 23, -112, 38, 0, 21, -66, 22, -65, 0, -44, 1, 1, 2, 1, 2, 1, 2, 23, -112, 6, 0, 21, -66, 23, -62, 0, -44, 1, 1, 2, 1, 2, 1, 2, 23, -112, -58, 0, 13, -63, 27, -16, 0, -114, 1, 0, 3, 0, 3, 0, 3, 3, -97, -81, 0, 15, 34, 12, -94, 0, -44, 1, 0, 2, 0, 2, 0, 0, 23, -112, 70, 1, 15, 34, 8, 34, 0, -56, 1, 0, 2, 0, 2, 0, 0, 23, -112, -31, 1, 15, 13, 6, 117, 0, -44, 1, 0, 0, 0, 2, 0, 2, 23, -112, -58, 1, 13, -9, 6, 117, 0, -44, 1, 0, 0, 1, 2, 1, 2, 23, -112, -26, 1, 13, -36, 8, 34, 0, -56, 1, 1, 2, 1, 2, 0, 0, 23, -112, 33, 0, 15, 34, 10, -31, 0, -44, 1, 0, 0, 0, 2, 0, 2, 23, -112, 102, 1, 13, -27, 12, -94, 0, -44, 1, 1, 2, 1, 2, 0, 0, 23, -112, 38, 1, 15, 34, 12, -94, 0, -44, 1, 0, 2, 0, 2, 0, 0, 23, -112, 70, 1, 15, 34, 10, -31, 0, -44, 1, 0, 0, 0, 2, 0, 2, 23, -112, -90, 1, 13, -27, 10, -31, 0, -44, 1, 0, 0, 1, 2, 1, 2, 23, -112, 38, 0, 20, 71, 6, 64, 0, -36, 1, 1, 2, 1, 2, 1, 2, 23, -112, -90, 0, 20, 71, 3, -64, 0, -36, 1, 1, 2, 1, 2, 1, 2, 23, -112, -58, 0, 23, -72, 3, -64, 0, -36, 1, 0, 2, 0, 2, 0, 2, 23, -112, -122, 0, 23, -72, 4, -62, 0, -36, 1, 0, 2, 0, 2, 0, 2, 23, -112, -90, 0, 23, -72, 5, 67, 0, -36, 1, 0, 2, 0, 2, 0, 2, 23, -112, 102, 0, 23, -72, 6, 63, 0, -36, 1, 0, 2, 0, 2, 0, 2, 23, -112, -90, 0, 23, -50, 7, -60, 0, -89, 1, 0, 2, 0, 2, 0, 0, 23, -112, -122, 0, 20, 59, 7, -60, 0, -89, 1, 1, 2, 1, 2, 0, 0, 23, -112, -26, 0, 20, 68, 2, 53, 0, -96, 1, 0, 0, 1, 2, 1, 2, 23, -112, 6, 0, 23, -60, 2, 53, 0, -96, 1, 0, 0, 0, 2, 0, 2, 23, -112, 6, 2, 3, -53, 10, 64, 0, -36, 1, 2, 1, 1, 2, 1, 2, 23, -112, -122, 2, 3, -53, 8, -58, 0, -36, 1, 1, 2, 1, 2, 2, 1, 23, -112, 38, 2, 3, -68, 7, -48, 0, -36, 1, 0, 0, 1, 2, 1, 2, 23, -112, 70, 2, 3, -68, 11, 56, 0, -36, 1, 1, 2, 1, 2, 0, 0, 23, -112, -122, 0, 6, 64, 7, -63, 0, 100, 0, 0, 1, 0, 0, -49, 0, 6, 0, 8, 81, 0, 51, 0, 0, 1, 0, 0, 15, 0, 0, 37, 8, 93, 0, -44, 1, 0, 0, 0, 2, 0, 2, 23, -112, -26, 0, 0, 37, 10, -91, 0, -44, 1, 1, 1, 0, 2, 0, 0, 23, -112, -58, 1, 6, -64, 12, 62, 0, -36, 1, 0, 2, 0, 2, 0, 2, 23, -112, 70, 1, 6, -64, 9, -67, 0, -36, 1, 0, 2, 0, 2, 0, 2, 23, -112, 6, 1, 0, 37, 8, 93, 0, -44, 1, 0, 0, 0, 2, 0, 2, 23, -112, -122, 1, 0, 37, 10, -91, 0, -44, 1, 1, 1, 0, 2, 0, 0, 23, -112, 102, 1, 6, -64, 6, -64, 0, -36, 1, 0, 2, 0, 2, 0, 2, 23, -112, -58, 1, 4, 77, 11, -64, 0, -36, 1, 1, 2, 1, 2, 1, 2, 23, -112, -26, 1, 4, 77, 10, -69, 0, -36, 1, 1, 2, 1, 2, 1, 2, 23, -112, -58, 1, 4, 77, 7, -64, 0, -36, 1, 1, 2, 1, 2, 1, 2, 23, -112, -26, 1, 4, 77, 6, -64, 0, -36, 1, 1, 2, 1, 2, 1, 2, 23, -112, -26, 1, 9, -56, 21, -71, 0, -44, 1, 0, 3, 0, 3, 0, 3, 23, -112, -122, 2, 5, 42, 11, 25, 0, -36, 1, 0, 2, 0, 2, 0, 0, 23, -112, -122, 2, 5, 25, 8, 0, 0, -36, 1, 0, 2, 0, 2, 0, 2, 23, -112, -122)
|
||||
|
||||
fun replaceValues() {
|
||||
val region = Rs2MapEditor.region
|
||||
val baseX = ((region shr 8) shl 6)
|
||||
val baseY = ((region and 0xFF) shl 6)
|
||||
val x = (region shr 8) and 0xFF
|
||||
val y = region and 0xFF
|
||||
|
||||
val data = MapTileEncoder().write(MapTileParser.definition)
|
||||
val mergedData = data.plus(endData)
|
||||
val dataSize = data.size
|
||||
|
||||
println("\n\n\n\n\n\nWriting data size: $dataSize")
|
||||
println("NEW SIZE: " + mergedData.size)
|
||||
|
||||
if (data != null || dataSize < 50000) {
|
||||
Rs2MapEditor.library.put(Indices.LANDSCAPES, "m${x}_${y}", mergedData)
|
||||
Rs2MapEditor.library.update()
|
||||
} else {
|
||||
System.err.println("Something went VERY wrong!")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package world
|
||||
|
||||
@JvmInline
|
||||
value class MapObject(val hash: Long) {
|
||||
|
||||
constructor(id: Int, x: Int, y: Int, plane: Int, type: Int, rotation: Int) : this(getHash(id, x, y, plane, type, rotation))
|
||||
|
||||
val id: Int
|
||||
get() = getId(hash)
|
||||
val x: Int
|
||||
get() = getX(hash)
|
||||
val y: Int
|
||||
get() = getY(hash)
|
||||
val plane: Int
|
||||
get() = getPlane(hash)
|
||||
val type: Int
|
||||
get() = getType(hash)
|
||||
val rotation: Int
|
||||
get() = getRotation(hash)
|
||||
|
||||
companion object {
|
||||
|
||||
fun getHash(id: Int, x: Int, y: Int, plane: Int, type: Int, rotation: Int): Long {
|
||||
return getHash(id.toLong(), x.toLong(), y.toLong(), plane.toLong(), type.toLong(), rotation.toLong())
|
||||
}
|
||||
|
||||
fun getHash(id: Long, x: Long, y: Long, plane: Long, type: Long, rotation: Long): Long {
|
||||
return rotation + (type shl 2) + (plane shl 7) + (y shl 9) + (x shl 23) + (id shl 37)
|
||||
}
|
||||
|
||||
fun getId(hash: Long): Int = (hash shr 37 and 0x1ffff).toInt()
|
||||
|
||||
fun getX(hash: Long): Int = (hash shr 23 and 0x3fff).toInt()
|
||||
|
||||
fun getY(hash: Long): Int = (hash shr 9 and 0x3fff).toInt()
|
||||
|
||||
fun getPlane(hash: Long): Int = (hash shr 7 and 0x3).toInt()
|
||||
|
||||
fun getType(hash: Long): Int = (hash shr 2 and 0x1f).toInt()
|
||||
|
||||
fun getRotation(hash: Long): Int = (hash and 0x3).toInt()
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
package world
|
||||
|
||||
@JvmInline
|
||||
value class MapTile(val hash: Long) {
|
||||
|
||||
constructor(
|
||||
height: Int = 0,
|
||||
opcode: Int = 0,
|
||||
overlay: Int = 0,
|
||||
path: Int = 0,
|
||||
rotation: Int = 0,
|
||||
settings: Int = 0,
|
||||
underlay: Int = 0
|
||||
) : this(getHash(height, opcode, overlay, path, rotation, settings, underlay))
|
||||
|
||||
val height: Int
|
||||
get() = getHeight(hash)
|
||||
|
||||
val attrOpcode: Int
|
||||
get() = getOpcode(hash)
|
||||
|
||||
val overlayId: Int
|
||||
get() = getOverlay(hash)
|
||||
|
||||
val overlayPath: Int
|
||||
get() = getPath(hash)
|
||||
|
||||
val overlayRotation: Int
|
||||
get() = getRotation(hash)
|
||||
|
||||
val settings: Int
|
||||
get() = getSettings(hash)
|
||||
|
||||
val underlayId: Int
|
||||
get() = getUnderlay(hash)
|
||||
|
||||
fun isTile(flag: Int) = settings and flag == flag
|
||||
|
||||
companion object {
|
||||
|
||||
val EMPTY = MapTile()
|
||||
|
||||
fun getHash(height: Int, opcode: Int, overlay: Int, path: Int, rotation: Int, settings: Int, underlay: Int): Long {
|
||||
return getHash(height.toLong(), opcode.toLong(), overlay.toLong(), path.toLong(), rotation.toLong(), settings.toLong(), underlay.toLong())
|
||||
}
|
||||
|
||||
fun getHash(height: Long, opcode: Long, overlay: Long, path: Long, rotation: Long, settings: Long, underlay: Long): Long {
|
||||
return height + (opcode shl 8) + (overlay shl 16) + (path shl 24) + (rotation shl 32) + (settings shl 40) + (underlay shl 48)
|
||||
}
|
||||
|
||||
fun getHeight(hash: Long): Int = (hash and 0xff).toInt()
|
||||
fun getOpcode(hash: Long): Int = (hash shr 8 and 0xff).toInt()
|
||||
fun getOverlay(hash: Long): Int = (hash shr 16 and 0xff).toInt()
|
||||
fun getPath(hash: Long): Int = (hash shr 24 and 0xff).toInt()
|
||||
fun getRotation(hash: Long): Int = (hash shr 32 and 0xff).toInt()
|
||||
fun getSettings(hash: Long): Int = (hash shr 40 and 0xff).toInt()
|
||||
fun getUnderlay(hash: Long): Int = (hash shr 48 and 0xff).toInt()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue