mirror of
https://gitlab.com/2009scape/tools/2009scape-map-viewer.git
synced 2026-08-01 14:39:25 -06:00
Functional writing to cache location. TODO: Figure out what data is being tacked onto the end of the underlay data
This commit is contained in:
parent
4c4af5da0a
commit
c83268feab
6 changed files with 90 additions and 23 deletions
|
|
@ -1,8 +1,11 @@
|
||||||
|
|
||||||
import com.displee.cache.CacheLibrary
|
import com.displee.cache.CacheLibrary
|
||||||
import com.formdev.flatlaf.FlatDarculaLaf
|
import com.formdev.flatlaf.FlatDarculaLaf
|
||||||
import decoders.FloorUnderlayConfiguration
|
import decoders.FloorUnderlayConfiguration
|
||||||
import decoders.MapTileParser
|
import decoders.MapTileParser
|
||||||
import definitions.UnderlayDefinition
|
import definitions.UnderlayDefinition
|
||||||
|
import encoder.MapTileWriter
|
||||||
|
import world.MapTile
|
||||||
import java.awt.*
|
import java.awt.*
|
||||||
import java.awt.event.KeyEvent
|
import java.awt.event.KeyEvent
|
||||||
import java.awt.event.MouseAdapter
|
import java.awt.event.MouseAdapter
|
||||||
|
|
@ -13,7 +16,8 @@ import kotlin.system.exitProcess
|
||||||
|
|
||||||
object Rs2MapEditor {
|
object Rs2MapEditor {
|
||||||
|
|
||||||
val library = CacheLibrary.create("/home/ceikry/IdeaProjects/rs09-remake/Server/data/cache/")
|
val library = CacheLibrary.create("K:\\RSPSDev\\2-009Scape-578\\Server\\data\\cache")
|
||||||
|
var region = 12850 // Lumbridge
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|
@ -114,7 +118,7 @@ object Rs2MapEditor {
|
||||||
selectedPointX = e.component.bounds.location.x / cellX
|
selectedPointX = e.component.bounds.location.x / cellX
|
||||||
selectedPointY = e.component.bounds.location.y / cellY
|
selectedPointY = e.component.bounds.location.y / cellY
|
||||||
statusLabel.foreground = Color.YELLOW
|
statusLabel.foreground = Color.YELLOW
|
||||||
statusLabel.text = "<html>Region: ${MapTileParser.region} | " +
|
statusLabel.text = "<html>Region: $region | " +
|
||||||
"Local Coordinates: [$selectedPointX, $selectedPointY] | " +
|
"Local Coordinates: [$selectedPointX, $selectedPointY] | " +
|
||||||
"Global Coordinates: [${MapTileParser.coordinateX(selectedPointX)}, ${MapTileParser.coordinateX(selectedPointY)}] | " +
|
"Global Coordinates: [${MapTileParser.coordinateX(selectedPointX)}, ${MapTileParser.coordinateX(selectedPointY)}] | " +
|
||||||
"Viewing Underlay: ${MapTileParser.definition.getTile(selectedPointX, selectedPointY, 0).underlayId} | " +
|
"Viewing Underlay: ${MapTileParser.definition.getTile(selectedPointX, selectedPointY, 0).underlayId} | " +
|
||||||
|
|
@ -130,6 +134,7 @@ object Rs2MapEditor {
|
||||||
override fun mouseClicked(e: MouseEvent) {
|
override fun mouseClicked(e: MouseEvent) {
|
||||||
if (SwingUtilities.isLeftMouseButton(e)) {
|
if (SwingUtilities.isLeftMouseButton(e)) {
|
||||||
if (selectedUnderlayId != null) {
|
if (selectedUnderlayId != null) {
|
||||||
|
val originalTile = MapTileParser.definition.getTile(selectedPointX, selectedPointY, 0)
|
||||||
val underlayID = selectedUnderlayId
|
val underlayID = selectedUnderlayId
|
||||||
val point = Point(selectedPointX, selectedPointY)
|
val point = Point(selectedPointX, selectedPointY)
|
||||||
val oldValue = colorPointMap[point]
|
val oldValue = colorPointMap[point]
|
||||||
|
|
@ -137,6 +142,9 @@ object Rs2MapEditor {
|
||||||
println("UPDATED UNDERLAY VALUES @ [${point.x}, ${point.y}] [$oldValue >> ${colorPointMap[point]}]")
|
println("UPDATED UNDERLAY VALUES @ [${point.x}, ${point.y}] [$oldValue >> ${colorPointMap[point]}]")
|
||||||
defaultBackground = underlayMap[selectedUnderlayId]?.getRGB()!!
|
defaultBackground = underlayMap[selectedUnderlayId]?.getRGB()!!
|
||||||
background = underlayMap[selectedUnderlayId]?.getRGB()
|
background = underlayMap[selectedUnderlayId]?.getRGB()
|
||||||
|
|
||||||
|
// Update map tile 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)) {
|
} else if (SwingUtilities.isRightMouseButton(e)) {
|
||||||
val point = Point(selectedPointX, selectedPointY)
|
val point = Point(selectedPointX, selectedPointY)
|
||||||
|
|
@ -258,8 +266,6 @@ object Rs2MapEditor {
|
||||||
}
|
}
|
||||||
val text = JLabel("$id")
|
val text = JLabel("$id")
|
||||||
text.foreground = Color((color.rgb).inv()).brighter()
|
text.foreground = Color((color.rgb).inv()).brighter()
|
||||||
val defaultBackground = color
|
|
||||||
|
|
||||||
|
|
||||||
minimumSize = Dimension(size, size)
|
minimumSize = Dimension(size, size)
|
||||||
maximumSize = Dimension(size, size)
|
maximumSize = Dimension(size, size)
|
||||||
|
|
@ -283,10 +289,10 @@ object Rs2MapEditor {
|
||||||
|
|
||||||
override fun mouseClicked(e: MouseEvent) {
|
override fun mouseClicked(e: MouseEvent) {
|
||||||
if (SwingUtilities.isLeftMouseButton(e)) {
|
if (SwingUtilities.isLeftMouseButton(e)) {
|
||||||
when (selectedUnderlayId) {
|
when (id) {
|
||||||
is Int -> {
|
is Int -> {
|
||||||
selectedUnderlayId = id as Int
|
selectedUnderlayId = id
|
||||||
statusLabel.text = "<html>Region: ${MapTileParser.region} | " +
|
statusLabel.text = "<html>Region: $region | " +
|
||||||
"Local Coordinates: [$selectedPointX, $selectedPointY] | " +
|
"Local Coordinates: [$selectedPointX, $selectedPointY] | " +
|
||||||
"Global Coordinates: [${MapTileParser.coordinateX(selectedPointX)}, ${MapTileParser.coordinateX(selectedPointY)}] | " +
|
"Global Coordinates: [${MapTileParser.coordinateX(selectedPointX)}, ${MapTileParser.coordinateX(selectedPointY)}] | " +
|
||||||
"Viewing Underlay: ${MapTileParser.definition.getTile(selectedPointX, selectedPointY, 0).underlayId} | " +
|
"Viewing Underlay: ${MapTileParser.definition.getTile(selectedPointX, selectedPointY, 0).underlayId} | " +
|
||||||
|
|
@ -308,6 +314,8 @@ object Rs2MapEditor {
|
||||||
add(label)
|
add(label)
|
||||||
addActionListener {
|
addActionListener {
|
||||||
println("User attempting to commit")
|
println("User attempting to commit")
|
||||||
|
MapTileWriter.replaceValues()
|
||||||
|
println("Wrote data to the cache!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ object FloorUnderlayConfiguration {
|
||||||
val buffer = ByteBuffer.wrap(it.data)
|
val buffer = ByteBuffer.wrap(it.data)
|
||||||
val definition = FloorUnderlayDecoder().decode(buffer)
|
val definition = FloorUnderlayDecoder().decode(buffer)
|
||||||
floorUnderlays[it.id] = definition
|
floorUnderlays[it.id] = definition
|
||||||
println(definition.toString())
|
//println(definition.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,19 +37,10 @@ class MapTileDecoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (height != 0 || attrOpcode != 0 || overlayPath != 0 || overlayRotation != 0 || overlayId != 0 || settings != 0 || underlayId != 0) {
|
if (height != 0 || attrOpcode != 0 || overlayPath != 0 || overlayRotation != 0 || overlayId != 0 || settings != 0 || underlayId != 0) {
|
||||||
definition.setTile(localX, localY, plane, MapTile(
|
definition.setTile(localX, localY, plane, MapTile(height, attrOpcode, overlayId, overlayPath, overlayRotation, settings, underlayId))
|
||||||
height,
|
|
||||||
attrOpcode,
|
|
||||||
overlayId,
|
|
||||||
overlayPath,
|
|
||||||
overlayRotation,
|
|
||||||
settings,
|
|
||||||
underlayId)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -8,8 +8,6 @@ object MapTileParser {
|
||||||
|
|
||||||
val definition = MapDefinition()
|
val definition = MapDefinition()
|
||||||
|
|
||||||
val region = 12850 // Lumbridge
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|
||||||
|
|
@ -31,23 +29,25 @@ object MapTileParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
val region = region
|
val region = Rs2MapEditor.region
|
||||||
val baseX = ((region shr 8) shl 6)
|
val baseX = ((region shr 8) shl 6)
|
||||||
val baseY = ((region and 0xFF) shl 6)
|
val baseY = ((region and 0xFF) shl 6)
|
||||||
val x = (region shr 8) and 0xFF
|
val x = (region shr 8) and 0xFF
|
||||||
val y = region and 0xFF
|
val y = region and 0xFF
|
||||||
val mapData = Rs2MapEditor.library.data(5,"m${x}_${y}")
|
val mapData = Rs2MapEditor.library.data(5,"m${x}_${y}")
|
||||||
|
|
||||||
|
println("Parsing data size: ${mapData!!.size}")
|
||||||
|
println(mapData.contentToString())
|
||||||
MapTileDecoder().readLoop(definition, ByteBuffer.wrap(mapData))
|
MapTileDecoder().readLoop(definition, ByteBuffer.wrap(mapData))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun coordinateX(x: Int): Int {
|
fun coordinateX(x: Int): Int {
|
||||||
val baseX = ((region shr 8) shl 6)
|
val baseX = ((Rs2MapEditor.region shr 8) shl 6)
|
||||||
return x + baseX
|
return x + baseX
|
||||||
}
|
}
|
||||||
|
|
||||||
fun coordinateY(y: Int): Int {
|
fun coordinateY(y: Int): Int {
|
||||||
val baseY = ((region and 0xFF) shl 6)
|
val baseY = ((Rs2MapEditor.region and 0xFF) shl 6)
|
||||||
return y + baseY
|
return y + baseY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
35
src/main/kotlin/encoder/MapTileEncoder.kt
Normal file
35
src/main/kotlin/encoder/MapTileEncoder.kt
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
package encoder
|
||||||
|
|
||||||
|
import definitions.MapDefinition
|
||||||
|
import java.nio.ByteBuffer
|
||||||
|
|
||||||
|
class MapTileEncoder {
|
||||||
|
|
||||||
|
fun write(definition: MapDefinition): ByteArray {
|
||||||
|
val buffer = ByteBuffer.allocate(80000)
|
||||||
|
for (plane in 0 until 4) {
|
||||||
|
for (localX in 0 until 64) {
|
||||||
|
for (localY in 0 until 64) {
|
||||||
|
val tile = definition.getTile(localX, localY, plane)
|
||||||
|
if (tile.underlayId != 0) {
|
||||||
|
buffer.put(((tile.underlayId + 81) and 0xFF).toByte())
|
||||||
|
}
|
||||||
|
if (tile.settings != 0) {
|
||||||
|
buffer.put(((tile.settings + 49) and 0xFF).toByte())
|
||||||
|
}
|
||||||
|
if (tile.attrOpcode != 0) {
|
||||||
|
buffer.put((tile.attrOpcode and 0xFF).toByte())
|
||||||
|
buffer.put((tile.overlayId and 0xFF).toByte())
|
||||||
|
}
|
||||||
|
if (tile.height == 0) {
|
||||||
|
buffer.put((0).toByte())
|
||||||
|
} else {
|
||||||
|
buffer.put((1).toByte())
|
||||||
|
buffer.put((tile.height and 0xFF).toByte())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buffer.array().copyOf(buffer.position())
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/main/kotlin/encoder/MapTileWriter.kt
Normal file
33
src/main/kotlin/encoder/MapTileWriter.kt
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
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!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue