diff --git a/src/main/kotlin/Rs2MapEditor.kt b/src/main/kotlin/Rs2MapEditor.kt index c3a439c..f5a469f 100644 --- a/src/main/kotlin/Rs2MapEditor.kt +++ b/src/main/kotlin/Rs2MapEditor.kt @@ -5,7 +5,7 @@ import cacheops.cache.definition.decoder.FloorUnderlayConfiguration import cacheops.cache.definition.decoder.MapTileParser import cacheops.cache.definition.decoder.NPC import cacheops.cache.definition.decoder.NPCSpawnParser -import cacheops.cache.definition.encoder.MapTileWriter +import cacheops.cache.definition.encoder.NPCSpawnEncoder import com.displee.cache.CacheLibrary import com.formdev.flatlaf.FlatDarculaLaf import const.Image.YELLOW_DOT @@ -13,15 +13,14 @@ import java.awt.* import java.awt.event.KeyEvent import java.awt.event.MouseAdapter import java.awt.event.MouseEvent -import java.lang.StringBuilder import javax.swing.* import javax.swing.border.* import kotlin.system.exitProcess object Rs2MapEditor { - val library = CacheLibrary.create("/home/ceikry/IdeaProjects/rs09-remake/Server/data/cache/") - var region = 7474 // Lumbridge + val library = CacheLibrary.create("K:\\RSPSDev\\2-009Scape-578\\Server\\data\\cache") + var region = 12853 var npcs = NPCSpawnParser.parseNPCSpawns(region) val npcRows = ArrayList() lateinit var mapPanel: MapPane @@ -504,7 +503,9 @@ object Rs2MapEditor { add(label) addActionListener { println("User attempting to commit") - MapTileWriter.replaceValues() + // TODO: DISABLED FOR NOW + //MapTileWriter.replaceValues() + NPCSpawnEncoder.write(npcs) println("Wrote data to the cache!") } } diff --git a/src/main/kotlin/cacheops/cache/definition/data/AtmosphereDefinition.kt b/src/main/kotlin/cacheops/cache/definition/data/AtmosphereDefinition.kt new file mode 100644 index 0000000..bfef0c8 --- /dev/null +++ b/src/main/kotlin/cacheops/cache/definition/data/AtmosphereDefinition.kt @@ -0,0 +1,19 @@ +package cacheops.cache.definition.data + +import cacheops.cache.Definition +import ext.Vector3f + +//TODO: Maybe finish and come back who knows. +data class AtmosphereDefinition( + override var id: Int = -1, + val DEFAULT_SKY_COLOR: Int = 0x17c439a8, + val DEFAULT_SUN_COLOR: Int = 0x36dac459, + val DEFAULT_SUN_X_POSITION: Float = 0.69921875F, + val DEFAULT_SUN_Y_POSITION: Float = 1.2F, + val DEFAULT_SUN_X_ANGLE: Int = -50, + val DEFAULT_SUN_Y_ANGLE: Int = -60, + val DEFAULT_SUN_Z_ANGLE: Int = -50, + val DEFAULT_SUN_ANGLE: Vector3f = Vector3f(DEFAULT_SUN_X_ANGLE.toFloat(), DEFAULT_SUN_Y_ANGLE.toFloat(), DEFAULT_SUN_Z_ANGLE.toFloat()), + val DEFAULT_SUN_SHININESS: Float = 1.1523438F, + +) : Definition \ No newline at end of file diff --git a/src/main/kotlin/cacheops/cache/definition/decoder/AtmosphereDecoder.kt b/src/main/kotlin/cacheops/cache/definition/decoder/AtmosphereDecoder.kt new file mode 100644 index 0000000..0ae15f4 --- /dev/null +++ b/src/main/kotlin/cacheops/cache/definition/decoder/AtmosphereDecoder.kt @@ -0,0 +1,7 @@ +package cacheops.cache.definition.decoder + +class AtmosphereDecoder { + + + +} \ No newline at end of file diff --git a/src/main/kotlin/cacheops/cache/definition/decoder/MapTileDecoder.kt b/src/main/kotlin/cacheops/cache/definition/decoder/MapTileDecoder.kt index 42e974c..83b91b6 100644 --- a/src/main/kotlin/cacheops/cache/definition/decoder/MapTileDecoder.kt +++ b/src/main/kotlin/cacheops/cache/definition/decoder/MapTileDecoder.kt @@ -7,7 +7,7 @@ import java.nio.ByteBuffer class MapTileDecoder { - fun readLoop(definition: MapDefinition, buffer: ByteBuffer) { + fun readLoop(definition: MapDefinition, buffer: ByteBuffer): ByteArray { for (plane in 0 until 4) { for (localX in 0 until 64) { for (localY in 0 until 64) { @@ -42,5 +42,6 @@ class MapTileDecoder { } } } + return buffer.array().copyOfRange(buffer.position(), buffer.capacity()) } } \ No newline at end of file diff --git a/src/main/kotlin/cacheops/cache/definition/decoder/MapTileParser.kt b/src/main/kotlin/cacheops/cache/definition/decoder/MapTileParser.kt index 96578a2..13e0583 100644 --- a/src/main/kotlin/cacheops/cache/definition/decoder/MapTileParser.kt +++ b/src/main/kotlin/cacheops/cache/definition/decoder/MapTileParser.kt @@ -8,6 +8,8 @@ object MapTileParser { val definition = MapDefinition() + lateinit var atmosphereDataTail: ByteArray + @JvmStatic fun main(args: Array) { @@ -35,8 +37,8 @@ object MapTileParser { val x = (region shr 8) and 0xFF val y = region and 0xFF val mapData = Rs2MapEditor.library.data(5,"m${x}_${y}") - - MapTileDecoder().readLoop(definition, ByteBuffer.wrap(mapData)) + println(mapData!!.size) + atmosphereDataTail = MapTileDecoder().readLoop(definition, ByteBuffer.wrap(mapData)) } fun coordinateX(x: Int): Int { diff --git a/src/main/kotlin/cacheops/cache/definition/encoder/MapTileWriter.kt b/src/main/kotlin/cacheops/cache/definition/encoder/MapTileWriter.kt index 30d90d2..ee65aa9 100644 --- a/src/main/kotlin/cacheops/cache/definition/encoder/MapTileWriter.kt +++ b/src/main/kotlin/cacheops/cache/definition/encoder/MapTileWriter.kt @@ -11,12 +11,11 @@ object MapTileWriter { 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) +// val combinedData = data.plus(MapTileParser.atmosphereDataTail) +// +// if (data != null) { +// Rs2MapEditor.library.put(Indices.LANDSCAPES, "m${x}_${y}", combinedData) // Rs2MapEditor.library.update() // } else { // System.err.println("Something went VERY wrong!") diff --git a/src/main/kotlin/cacheops/cache/definition/encoder/NPCSpawnEncoder.kt b/src/main/kotlin/cacheops/cache/definition/encoder/NPCSpawnEncoder.kt new file mode 100644 index 0000000..7ba087c --- /dev/null +++ b/src/main/kotlin/cacheops/cache/definition/encoder/NPCSpawnEncoder.kt @@ -0,0 +1,34 @@ +package cacheops.cache.definition.encoder + +import Rs2MapEditor +import cacheops.cache.definition.decoder.NPC +import const.Indices +import java.nio.ByteBuffer + +object NPCSpawnEncoder { + + fun write(npc: ArrayList) { + val buffer = ByteBuffer.allocate(10000) + + npc.forEach { + val formattedCoord = ((it.y or (it.x shl 7)) or (it.plane shl 14)) + buffer.putShort(formattedCoord.toShort()) + buffer.putShort(it.id.toShort()) + } + + val dataArray = buffer.array().copyOf(buffer.position()) + + 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 + + if (dataArray != null) { + Rs2MapEditor.library.put(Indices.LANDSCAPES, "n${x}_${y}", dataArray, intArrayOf(0,0,0,0)) + Rs2MapEditor.library.update() + } else { + System.err.println("Panic! Something went VERY wrong!") + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/const/Misc.kt b/src/main/kotlin/const/Misc.kt index 376b131..d22748c 100644 --- a/src/main/kotlin/const/Misc.kt +++ b/src/main/kotlin/const/Misc.kt @@ -3,4 +3,4 @@ package const import cacheops.cache.Cache import cacheops.cache.CacheDelegate -val cache: Cache = CacheDelegate("/home/ceikry/IdeaProjects/rs09-remake/Server/data/cache/") +val cache: Cache = CacheDelegate("K:\\RSPSDev\\2-009Scape-578\\Server\\data\\cache") diff --git a/src/main/kotlin/ext/Vector3f.kt b/src/main/kotlin/ext/Vector3f.kt new file mode 100644 index 0000000..2f92a40 --- /dev/null +++ b/src/main/kotlin/ext/Vector3f.kt @@ -0,0 +1,24 @@ +package ext + +class Vector3f(var x: Float, var y: Float, var z: Float) { + + override fun hashCode(): Int { + var result = x.hashCode() + result = 31 * result + y.hashCode() + result = 31 * result + z.hashCode() + return result + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as Vector3f + + if (x != other.x) return false + if (y != other.y) return false + if (z != other.z) return false + + return true + } +} \ No newline at end of file