mirror of
https://gitlab.com/2009scape/tools/2009scape-map-viewer.git
synced 2026-08-01 14:39:25 -06:00
haha color go workie
This commit is contained in:
parent
f2ff15a5aa
commit
37827a1263
5 changed files with 310 additions and 13 deletions
|
|
@ -17,7 +17,6 @@ import java.awt.*
|
||||||
import java.awt.event.KeyEvent
|
import java.awt.event.KeyEvent
|
||||||
import java.awt.event.MouseAdapter
|
import java.awt.event.MouseAdapter
|
||||||
import java.awt.event.MouseEvent
|
import java.awt.event.MouseEvent
|
||||||
import java.lang.Exception
|
|
||||||
import javax.swing.*
|
import javax.swing.*
|
||||||
import javax.swing.border.*
|
import javax.swing.border.*
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
@ -141,16 +140,28 @@ object Rs2MapEditor {
|
||||||
val border: Border = MatteBorder(1, 1, if (row == mapHeight) 1 else 0, if (column == mapWidth) 1 else 0, Color.GRAY)
|
val border: Border = MatteBorder(1, 1, if (row == mapHeight) 1 else 0, if (column == mapWidth) 1 else 0, Color.GRAY)
|
||||||
val flippedY = (64 - row) - 1
|
val flippedY = (64 - row) - 1
|
||||||
val point = Point(column, flippedY)
|
val point = Point(column, flippedY)
|
||||||
colorPointMap[point] = MapTileParser.definition.getTile(column, flippedY, plane).underlayId
|
colorPointMap[point] = MapTileParser.definition.getTile(column, flippedY, plane).underlayId - 1
|
||||||
val mapCell = MapCell()
|
val mapCell = MapCell()
|
||||||
|
|
||||||
val overlayID = MapTileParser.definition.getTile(column, flippedY, plane).overlayId
|
var overlayID = (MapTileParser.definition.getTile(column, flippedY, plane).overlayId - 1)
|
||||||
val floDef = overlayMap[overlayID]!!
|
if (overlayID < 0) {
|
||||||
|
overlayID = 0
|
||||||
|
}
|
||||||
|
var underlayID = (MapTileParser.definition.getTile(column, flippedY, plane).underlayId - 1)
|
||||||
|
if (underlayID < 0) {
|
||||||
|
underlayID = 0
|
||||||
|
}
|
||||||
|
val fluDef = underlayMap[underlayID]
|
||||||
|
val floDef = overlayMap[overlayID]
|
||||||
|
|
||||||
if (overlayID == 0) {
|
if (underlayID == 0) {
|
||||||
mapCell.background = underlayMap[MapTileParser.definition.getTile(column, flippedY, plane).underlayId]!!.getRGB()
|
mapCell.background = Color(overlayMap[overlayID + 1]!!.color)
|
||||||
|
} else if (overlayID == 0) {
|
||||||
|
mapCell.background = fluDef!!.getRGB()
|
||||||
|
} else if (floDef!!.blendColor != -1) {
|
||||||
|
mapCell.background = Color(floDef.blendColor)
|
||||||
} else {
|
} else {
|
||||||
mapCell.background = overlayMap[overlayID]!!.getRGB()
|
mapCell.background = floDef.getRGB()
|
||||||
}
|
}
|
||||||
|
|
||||||
mapCell.border = border
|
mapCell.border = border
|
||||||
|
|
@ -512,9 +523,9 @@ object Rs2MapEditor {
|
||||||
selectedUnderlayId = id
|
selectedUnderlayId = id
|
||||||
}
|
}
|
||||||
statusLabel.text = "<html>Region: $region | " +
|
statusLabel.text = "<html>Region: $region | " +
|
||||||
"Local Coordinates: [$selectedPointX, $selectedPointY] | " +
|
"Local Coordinates: [$selectedPointX, $selectedPointY, $plane] | " +
|
||||||
"Global Coordinates: [${MapTileParser.coordinateX(selectedPointX)}, ${MapTileParser.coordinateX(selectedPointY)}] | " +
|
"Global Coordinates: [${MapTileParser.coordinateX(selectedPointX)}, ${MapTileParser.coordinateX(selectedPointY)}, $plane] | " +
|
||||||
"Viewing Underlay: ${MapTileParser.definition.getTile(selectedPointX, selectedPointY, 0).underlayId} | " +
|
"Viewing Underlay: ${MapTileParser.definition.getTile(selectedPointX, selectedPointY, 0).underlayId - 1} | " +
|
||||||
"Selected Underlay: ${if (selectedUnderlayId == null) "<font color='red'>No underlay selected!</font>" else "$selectedUnderlayId"}</html>"
|
"Selected Underlay: ${if (selectedUnderlayId == null) "<font color='red'>No underlay selected!</font>" else "$selectedUnderlayId"}</html>"
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
|
|
||||||
9
src/main/kotlin/cacheops/cache/definition/data/BlendedTextureDefinition.kt
vendored
Normal file
9
src/main/kotlin/cacheops/cache/definition/data/BlendedTextureDefinition.kt
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
package cacheops.cache.definition.data
|
||||||
|
|
||||||
|
import cacheops.cache.Definition
|
||||||
|
|
||||||
|
data class BlendedTextureDefinition(
|
||||||
|
override var id: Int = -1,
|
||||||
|
var renderOnMap: Boolean = false,
|
||||||
|
var blendedColor: Int = -1
|
||||||
|
) : Definition
|
||||||
95
src/main/kotlin/cacheops/cache/definition/decoder/BlendedTextureDecoder.kt
vendored
Normal file
95
src/main/kotlin/cacheops/cache/definition/decoder/BlendedTextureDecoder.kt
vendored
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
package cacheops.cache.definition.decoder
|
||||||
|
|
||||||
|
import cacheops.cache.Cache
|
||||||
|
import cacheops.cache.DefinitionDecoder
|
||||||
|
import cacheops.cache.buffer.read.BufferReader
|
||||||
|
import cacheops.cache.buffer.read.Reader
|
||||||
|
import cacheops.cache.definition.data.BlendedTextureDefinition
|
||||||
|
import const.Indices
|
||||||
|
|
||||||
|
class BlendedTextureDecoder(cache: Cache) : DefinitionDecoder<BlendedTextureDefinition>(cache, Indices.MATERIALS) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val blendedTextureDef = HashMap<Int, BlendedTextureDefinition>()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun create() = BlendedTextureDefinition()
|
||||||
|
|
||||||
|
var metricsCount = 0
|
||||||
|
|
||||||
|
override val last: Int
|
||||||
|
get() = metricsCount
|
||||||
|
|
||||||
|
init {
|
||||||
|
val data = getData(0, 0)
|
||||||
|
if (data != null) {
|
||||||
|
decode(BufferReader(data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun decode(buffer: Reader) {
|
||||||
|
metricsCount = buffer.readShort()
|
||||||
|
for (id in 0 until metricsCount) {
|
||||||
|
if (buffer.readUnsignedBoolean()) {
|
||||||
|
blendedTextureDef[id] = BlendedTextureDefinition(id = id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (texture in blendedTextureDef.values) { // J
|
||||||
|
texture.renderOnMap = !buffer.readUnsignedBoolean() // 0
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readUnsignedBoolean() // 1
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readUnsignedBoolean() // 1
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readByte().toByte() // 1
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readByte().toByte()
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readByte().toByte()
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readByte().toByte()
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
texture.blendedColor = buffer.readUnsignedShort()
|
||||||
|
println(texture.blendedColor)
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readByte().toByte()
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readByte().toByte()
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readUnsignedBoolean()
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readUnsignedBoolean()
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readByte().toByte()
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readUnsignedBoolean()
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readUnsignedBoolean()
|
||||||
|
}
|
||||||
|
for (texture in blendedTextureDef.values) {
|
||||||
|
buffer.readUnsignedBoolean()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun clear() {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun BlendedTextureDefinition.read(opcode: Int, buffer: Reader) {
|
||||||
|
throw IllegalStateException("Shouldn't be used.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -26,9 +26,6 @@ class FloorOverlayDecoder {
|
||||||
while (true) {
|
while (true) {
|
||||||
val opcode = buffer.unsignedByte()
|
val opcode = buffer.unsignedByte()
|
||||||
if (opcode == 0) {
|
if (opcode == 0) {
|
||||||
if (color == 12098407) {
|
|
||||||
color = waterColor
|
|
||||||
}
|
|
||||||
return OverlayDefinition(color, texture, hideUnderlay, blendColor, scale, blockShadow, aByte0, blendTexture, waterColor, waterScale, anInt0, waterIntensity)
|
return OverlayDefinition(color, texture, hideUnderlay, blendColor, scale, blockShadow, aByte0, blendTexture, waterColor, waterScale, anInt0, waterIntensity)
|
||||||
}
|
}
|
||||||
decodeOverlayType(opcode, buffer)
|
decodeOverlayType(opcode, buffer)
|
||||||
|
|
|
||||||
185
src/main/kotlin/worldmap/OverlayHandler.kt
Normal file
185
src/main/kotlin/worldmap/OverlayHandler.kt
Normal file
|
|
@ -0,0 +1,185 @@
|
||||||
|
package worldmap
|
||||||
|
|
||||||
|
import cacheops.cache.definition.data.OverlayDefinition
|
||||||
|
import cacheops.cache.definition.decoder.BlendedTextureDecoder
|
||||||
|
import cacheops.cache.definition.decoder.FloorOverlayConfiguration
|
||||||
|
import kotlin.math.pow
|
||||||
|
|
||||||
|
object OverlayHandler {
|
||||||
|
|
||||||
|
var blendedOverlayColors: IntArray = IntArray(FloorOverlayConfiguration.floorOverlays.size + 1)
|
||||||
|
var p: IntArray = IntArray(65536)
|
||||||
|
|
||||||
|
var f_l = (Math.random() * 11.0).toInt() - 5
|
||||||
|
var n = (Math.random() * 17.0).toInt() - 8
|
||||||
|
|
||||||
|
fun init() {
|
||||||
|
f(0)
|
||||||
|
f_l += -2 + (5.0 * Math.random()).toInt()
|
||||||
|
if (f_l < -8) {
|
||||||
|
f_l = -8
|
||||||
|
}
|
||||||
|
n += -2 + (Math.random() * 5.0).toInt()
|
||||||
|
if (f_l > 8) {
|
||||||
|
f_l = 8
|
||||||
|
}
|
||||||
|
if (n < -16) {
|
||||||
|
n = -16
|
||||||
|
}
|
||||||
|
if (n > 16) {
|
||||||
|
n = 16
|
||||||
|
}
|
||||||
|
setOverlayColorArray(((f_l shr 2) shl 10), n shr 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setOverlayColorArray(randomColorOffset1: Int, randomColorOffset2: Int) {
|
||||||
|
for (overlayId in 0 until FloorOverlayConfiguration.floorOverlays.size) {
|
||||||
|
blendedOverlayColors[overlayId + 1] = getOverlayColor(overlayId,randomColorOffset1,randomColorOffset2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getOverlayColor(id: Int, colorOffset1: Int, colorOffset2: Int): Int {
|
||||||
|
val floDefinition: OverlayDefinition = FloorOverlayConfiguration.floorOverlays[id] ?: return 0
|
||||||
|
var floorOverlayTexture = floDefinition.texture
|
||||||
|
if (floorOverlayTexture >= 0 && BlendedTextureDecoder.blendedTextureDef[floorOverlayTexture]!!.renderOnMap) {
|
||||||
|
floorOverlayTexture = -1
|
||||||
|
}
|
||||||
|
val negativeRGBColor: Int
|
||||||
|
if (floDefinition.blendColor >= 0) {
|
||||||
|
val floorOverlayBlendColor = floDefinition.blendColor
|
||||||
|
var offsetBlendedValue = ((floorOverlayBlendColor and 0x7F) + colorOffset2)
|
||||||
|
if (offsetBlendedValue < 0) {
|
||||||
|
offsetBlendedValue = 0
|
||||||
|
} else if (offsetBlendedValue > 127) {
|
||||||
|
offsetBlendedValue = 127
|
||||||
|
}
|
||||||
|
val combinedBlendedValue = ((floorOverlayBlendColor + (colorOffset1 and 0xfc00) + ((floorOverlayBlendColor and 0x380))) + offsetBlendedValue)
|
||||||
|
negativeRGBColor = (0xffffff.inv() or p[colorFunc2(colorFunc1(96, 2, combinedBlendedValue),-2045205981).toInt() and 0xffff])
|
||||||
|
} else if (floorOverlayTexture >= 0) {
|
||||||
|
negativeRGBColor = (0xffffff.inv() or p[colorFunc2(colorFunc1(96, 2, BlendedTextureDecoder.blendedTextureDef[floorOverlayTexture]!!.blendedColor),-2045205981).toInt() and 0xffff])
|
||||||
|
} else if (floDefinition.color == -1) {
|
||||||
|
negativeRGBColor = 0
|
||||||
|
} else {
|
||||||
|
val floorOverlayColor = floDefinition.color
|
||||||
|
var offsetColorValue = ((floorOverlayColor and 0x7f) + colorOffset2)
|
||||||
|
if (offsetColorValue < 0) {
|
||||||
|
offsetColorValue = 0
|
||||||
|
} else if (offsetColorValue > 127) {
|
||||||
|
offsetColorValue = 127
|
||||||
|
}
|
||||||
|
val combinedColorValue = (((colorOffset1 and 0xfc00) + floorOverlayColor) + ((floorOverlayColor and 0x380) + offsetColorValue))
|
||||||
|
negativeRGBColor = (0xffffff.inv() or p[colorFunc2(colorFunc1(96, 2, combinedColorValue),-2045205981).toInt() and 0xffff])
|
||||||
|
}
|
||||||
|
return negativeRGBColor
|
||||||
|
}
|
||||||
|
|
||||||
|
fun colorFunc1(i: Int, i_1_: Int, i_2_: Int): Int {
|
||||||
|
var i = i
|
||||||
|
if (i_1_ != 2) {
|
||||||
|
return 64
|
||||||
|
}
|
||||||
|
if (i_2_ == -2) {
|
||||||
|
return 12345678
|
||||||
|
}
|
||||||
|
if (i_2_ == -1) {
|
||||||
|
if (i >= 2) {
|
||||||
|
if (i > 126) {
|
||||||
|
i = 126
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
i = 2
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
i = i * (i_2_ and 0x7f) shr 7
|
||||||
|
if (i < 2) {
|
||||||
|
i = 2
|
||||||
|
} else if (i > 126) {
|
||||||
|
i = 126
|
||||||
|
}
|
||||||
|
return (0xff80 and i_2_) + i
|
||||||
|
}
|
||||||
|
|
||||||
|
fun colorFunc2(i: Int, i_1_: Int): Short {
|
||||||
|
return try {
|
||||||
|
val i_2_ = ((0xfddc and i) shr 10)
|
||||||
|
if (i_1_ != -2045205981) {
|
||||||
|
return 123.toShort()
|
||||||
|
}
|
||||||
|
var i_3_ = 0x384 and i shr 3
|
||||||
|
val i_4_ = 0x7f and i
|
||||||
|
i_3_ = if (i_4_ <= 64) i_4_ * i_3_ shr 7 else (127 - i_4_) * i_3_ shr 7
|
||||||
|
val i_5_ = i_3_ + i_4_
|
||||||
|
var i_6_: Int
|
||||||
|
do {
|
||||||
|
if (i_5_ == 0) {
|
||||||
|
i_6_ = i_3_ shl 1
|
||||||
|
if (!true) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i_6_ = (i_3_ shl 8) / i_5_
|
||||||
|
} while (false)
|
||||||
|
(i_5_ or (i_2_ shl 10 or i_6_ shr 4 shl 7)).toShort()
|
||||||
|
} catch (runtimeexception: RuntimeException) {
|
||||||
|
throw error("fuk")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun f(i: Int) {
|
||||||
|
val d = -0.015 + 0.03 * Math.random() + 0.7
|
||||||
|
var i_7_ = i
|
||||||
|
for (i_8_ in 0..511) {
|
||||||
|
val f = (0.0078125f + (i_8_ shr 3).toFloat() / 64.0f) * 360.0f
|
||||||
|
val f_9_ = (i_8_ and 0x7).toFloat() / 8.0f + 0.0625f
|
||||||
|
for (i_10_ in 0..127) {
|
||||||
|
val f_11_ = i_10_.toFloat() / 128.0f
|
||||||
|
var f_12_ = 0.0f
|
||||||
|
var f_13_ = 0.0f
|
||||||
|
var f_14_ = 0.0f
|
||||||
|
val f_15_ = f / 60.0f
|
||||||
|
val i_16_ = f_15_.toInt()
|
||||||
|
val i_17_ = i_16_ % 6
|
||||||
|
val f_18_ = f_15_ - i_16_.toFloat()
|
||||||
|
val f_19_ = f_11_ * (1.0f - f_9_)
|
||||||
|
val f_20_ = f_11_ * (-(f_18_ * f_9_) + 1.0f)
|
||||||
|
val f_21_ = f_11_ * (-(f_9_ * (-f_18_ + 1.0f)) + 1.0f)
|
||||||
|
if (i_17_ == 0) {
|
||||||
|
f_13_ = f_21_
|
||||||
|
f_14_ = f_19_
|
||||||
|
f_12_ = f_11_
|
||||||
|
} else if (i_17_ == 1) {
|
||||||
|
f_14_ = f_19_
|
||||||
|
f_13_ = f_11_
|
||||||
|
f_12_ = f_20_
|
||||||
|
} else if (i_17_ == 2) {
|
||||||
|
f_14_ = f_21_
|
||||||
|
f_13_ = f_11_
|
||||||
|
f_12_ = f_19_
|
||||||
|
} else if (i_17_ == 3) {
|
||||||
|
f_13_ = f_20_
|
||||||
|
f_12_ = f_19_
|
||||||
|
f_14_ = f_11_
|
||||||
|
} else if (i_17_ == 4) {
|
||||||
|
f_13_ = f_19_
|
||||||
|
f_12_ = f_21_
|
||||||
|
f_14_ = f_11_
|
||||||
|
} else if (i_17_ == 5) {
|
||||||
|
f_12_ = f_11_
|
||||||
|
f_13_ = f_19_
|
||||||
|
f_14_ = f_20_
|
||||||
|
}
|
||||||
|
f_12_ = f_12_.toDouble().pow(d).toFloat()
|
||||||
|
f_13_ = f_13_.toDouble().pow(d).toFloat()
|
||||||
|
f_14_ = f_14_.toDouble().pow(d).toFloat()
|
||||||
|
val i_22_ = (f_12_ * 256.0f).toInt()
|
||||||
|
val i_23_ = (f_13_ * 254.0f).toInt()
|
||||||
|
val i_24_ = (f_14_ * 256.0f).toInt()
|
||||||
|
val i_25_ = i_24_ + ((i_23_ shl 8) - 16777216 + (i_22_ shl 16))
|
||||||
|
p[i_7_++] = i_25_
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue