diff --git a/src/main/kotlin/Rs2MapEditor.kt b/src/main/kotlin/Rs2MapEditor.kt index 491d21a..58f46ea 100644 --- a/src/main/kotlin/Rs2MapEditor.kt +++ b/src/main/kotlin/Rs2MapEditor.kt @@ -1,8 +1,11 @@ + 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 @@ -13,7 +16,8 @@ import kotlin.system.exitProcess 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 fun main(args: Array) { @@ -114,7 +118,7 @@ object Rs2MapEditor { selectedPointX = e.component.bounds.location.x / cellX selectedPointY = e.component.bounds.location.y / cellY statusLabel.foreground = Color.YELLOW - statusLabel.text = "Region: ${MapTileParser.region} | " + + statusLabel.text = "Region: $region | " + "Local Coordinates: [$selectedPointX, $selectedPointY] | " + "Global Coordinates: [${MapTileParser.coordinateX(selectedPointX)}, ${MapTileParser.coordinateX(selectedPointY)}] | " + "Viewing Underlay: ${MapTileParser.definition.getTile(selectedPointX, selectedPointY, 0).underlayId} | " + @@ -130,6 +134,7 @@ object Rs2MapEditor { override fun mouseClicked(e: MouseEvent) { if (SwingUtilities.isLeftMouseButton(e)) { if (selectedUnderlayId != null) { + val originalTile = MapTileParser.definition.getTile(selectedPointX, selectedPointY, 0) val underlayID = selectedUnderlayId val point = Point(selectedPointX, selectedPointY) val oldValue = colorPointMap[point] @@ -137,6 +142,9 @@ object Rs2MapEditor { println("UPDATED UNDERLAY VALUES @ [${point.x}, ${point.y}] [$oldValue >> ${colorPointMap[point]}]") defaultBackground = 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)) { val point = Point(selectedPointX, selectedPointY) @@ -258,8 +266,6 @@ object Rs2MapEditor { } val text = JLabel("$id") text.foreground = Color((color.rgb).inv()).brighter() - val defaultBackground = color - minimumSize = Dimension(size, size) maximumSize = Dimension(size, size) @@ -283,10 +289,10 @@ object Rs2MapEditor { override fun mouseClicked(e: MouseEvent) { if (SwingUtilities.isLeftMouseButton(e)) { - when (selectedUnderlayId) { + when (id) { is Int -> { - selectedUnderlayId = id as Int - statusLabel.text = "Region: ${MapTileParser.region} | " + + selectedUnderlayId = id + statusLabel.text = "Region: $region | " + "Local Coordinates: [$selectedPointX, $selectedPointY] | " + "Global Coordinates: [${MapTileParser.coordinateX(selectedPointX)}, ${MapTileParser.coordinateX(selectedPointY)}] | " + "Viewing Underlay: ${MapTileParser.definition.getTile(selectedPointX, selectedPointY, 0).underlayId} | " + @@ -308,6 +314,8 @@ object Rs2MapEditor { add(label) addActionListener { println("User attempting to commit") + MapTileWriter.replaceValues() + println("Wrote data to the cache!") } } } diff --git a/src/main/kotlin/decoders/FloorUnderlayConfiguration.kt b/src/main/kotlin/decoders/FloorUnderlayConfiguration.kt index 91f43ef..55b443c 100644 --- a/src/main/kotlin/decoders/FloorUnderlayConfiguration.kt +++ b/src/main/kotlin/decoders/FloorUnderlayConfiguration.kt @@ -26,7 +26,7 @@ object FloorUnderlayConfiguration { val buffer = ByteBuffer.wrap(it.data) val definition = FloorUnderlayDecoder().decode(buffer) floorUnderlays[it.id] = definition - println(definition.toString()) + //println(definition.toString()) } } diff --git a/src/main/kotlin/decoders/MapTileDecoder.kt b/src/main/kotlin/decoders/MapTileDecoder.kt index 858d79a..843221a 100644 --- a/src/main/kotlin/decoders/MapTileDecoder.kt +++ b/src/main/kotlin/decoders/MapTileDecoder.kt @@ -37,19 +37,10 @@ class MapTileDecoder { } } if (height != 0 || attrOpcode != 0 || overlayPath != 0 || overlayRotation != 0 || overlayId != 0 || settings != 0 || underlayId != 0) { - definition.setTile(localX, localY, plane, MapTile( - height, - attrOpcode, - overlayId, - overlayPath, - overlayRotation, - settings, - underlayId) - ) + definition.setTile(localX, localY, plane, MapTile(height, attrOpcode, overlayId, overlayPath, overlayRotation, settings, underlayId)) } } } } } - } \ No newline at end of file diff --git a/src/main/kotlin/decoders/MapTileParser.kt b/src/main/kotlin/decoders/MapTileParser.kt index b10d81e..26600dd 100644 --- a/src/main/kotlin/decoders/MapTileParser.kt +++ b/src/main/kotlin/decoders/MapTileParser.kt @@ -8,8 +8,6 @@ object MapTileParser { val definition = MapDefinition() - val region = 12850 // Lumbridge - @JvmStatic fun main(args: Array) { @@ -31,23 +29,25 @@ object MapTileParser { } fun init() { - val region = region + 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 mapData = Rs2MapEditor.library.data(5,"m${x}_${y}") + println("Parsing data size: ${mapData!!.size}") + println(mapData.contentToString()) MapTileDecoder().readLoop(definition, ByteBuffer.wrap(mapData)) } fun coordinateX(x: Int): Int { - val baseX = ((region shr 8) shl 6) + val baseX = ((Rs2MapEditor.region shr 8) shl 6) return x + baseX } fun coordinateY(y: Int): Int { - val baseY = ((region and 0xFF) shl 6) + val baseY = ((Rs2MapEditor.region and 0xFF) shl 6) return y + baseY } } \ No newline at end of file diff --git a/src/main/kotlin/encoder/MapTileEncoder.kt b/src/main/kotlin/encoder/MapTileEncoder.kt new file mode 100644 index 0000000..5241a04 --- /dev/null +++ b/src/main/kotlin/encoder/MapTileEncoder.kt @@ -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()) + } +} \ No newline at end of file diff --git a/src/main/kotlin/encoder/MapTileWriter.kt b/src/main/kotlin/encoder/MapTileWriter.kt new file mode 100644 index 0000000..3901204 --- /dev/null +++ b/src/main/kotlin/encoder/MapTileWriter.kt @@ -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!") + } + } + +} \ No newline at end of file