diff --git a/cache-550/build.gradle.kts b/cache-550/build.gradle.kts new file mode 100644 index 00000000..52b6ba25 --- /dev/null +++ b/cache-550/build.gradle.kts @@ -0,0 +1,28 @@ +plugins { + `maven-publish` + kotlin("jvm") +} + +dependencies { + api(projects.cache) + + implementation(projects.buffer) + implementation(projects.util) +} + +publishing { + publications.create("maven") { + from(components["java"]) + + pom { + packaging = "jar" + name.set("OpenRS2 Cache (Build 550)") + description.set( + """ + A library for encoding and decoding files contained within the + RuneScape cache. It is only compatible with build 550. + """.trimIndent() + ) + } + } +} diff --git a/cache-550/src/main/kotlin/org/openrs2/cache/config/enum/EnumType.kt b/cache-550/src/main/kotlin/org/openrs2/cache/config/enum/EnumType.kt new file mode 100644 index 00000000..49b441ee --- /dev/null +++ b/cache-550/src/main/kotlin/org/openrs2/cache/config/enum/EnumType.kt @@ -0,0 +1,100 @@ +package org.openrs2.cache.config.enum + +import io.netty.buffer.ByteBuf +import it.unimi.dsi.fastutil.ints.Int2IntMap +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap +import it.unimi.dsi.fastutil.ints.Int2ObjectMap +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap +import org.openrs2.buffer.readString +import org.openrs2.buffer.writeString +import org.openrs2.cache.config.ConfigType +import org.openrs2.util.charset.Cp1252Charset + +public class EnumType(id: Int) : ConfigType(id) { + public var keyType: Char = 0.toChar() + public var valueType: Char = 0.toChar() + public var defaultString: String = "null" + public var defaultInt: Int = 0 + + // TODO(gpe): methods for manipulating the maps + private var strings: Int2ObjectMap? = null + private var ints: Int2IntMap? = null + + override fun read(buf: ByteBuf, code: Int) { + when (code) { + 1 -> keyType = Cp1252Charset.decode(buf.readByte()) + 2 -> valueType = Cp1252Charset.decode(buf.readByte()) + 3 -> defaultString = buf.readString() + 4 -> defaultInt = buf.readInt() + 5 -> { + val size = buf.readUnsignedShort() + val strings = Int2ObjectOpenHashMap() + + for (i in 0 until size) { + val key = buf.readInt() + strings[key] = buf.readString() + } + + this.strings = strings + } + 6 -> { + val size = buf.readUnsignedShort() + val ints = Int2IntOpenHashMap() + + for (i in 0 until size) { + val key = buf.readInt() + ints[key] = buf.readInt() + } + + this.ints = ints + } + else -> throw IllegalArgumentException("Unsupported config code: $code") + } + } + + override fun write(buf: ByteBuf) { + if (keyType.code != 0) { + buf.writeByte(1) + buf.writeByte(Cp1252Charset.encode(keyType).toInt()) + } + + if (valueType.code != 0) { + buf.writeByte(2) + buf.writeByte(Cp1252Charset.encode(valueType).toInt()) + } + + if (defaultString != "null") { + buf.writeByte(3) + buf.writeString(defaultString) + } + + if (defaultInt != 0) { + buf.writeByte(4) + buf.writeInt(defaultInt) + } + + val strings = strings + if (strings != null && strings.isNotEmpty()) { + buf.writeByte(5) + buf.writeShort(strings.size) + + for ((key, value) in strings.int2ObjectEntrySet()) { + buf.writeInt(key) + buf.writeString(value) + } + } + + val ints = ints + if (ints != null && ints.isNotEmpty()) { + buf.writeByte(6) + buf.writeShort(ints.size) + + for ((key, value) in ints.int2IntEntrySet()) { + buf.writeInt(key) + buf.writeInt(value) + } + } + + buf.writeByte(0) + } +} diff --git a/cache-550/src/main/kotlin/org/openrs2/cache/config/enum/EnumTypeList.kt b/cache-550/src/main/kotlin/org/openrs2/cache/config/enum/EnumTypeList.kt new file mode 100644 index 00000000..446bc4fe --- /dev/null +++ b/cache-550/src/main/kotlin/org/openrs2/cache/config/enum/EnumTypeList.kt @@ -0,0 +1,15 @@ +package org.openrs2.cache.config.enum + +import org.openrs2.cache.Cache +import org.openrs2.cache.Js5Archive +import org.openrs2.cache.config.ArchiveConfigTypeList + +public class EnumTypeList(cache: Cache) : ArchiveConfigTypeList( + cache, + archive = Js5Archive.CONFIG_ENUM, + fileBits = 8 +) { + override fun allocate(id: Int): EnumType { + return EnumType(id) + } +} diff --git a/cache-550/src/main/kotlin/org/openrs2/cache/config/param/ParamType.kt b/cache-550/src/main/kotlin/org/openrs2/cache/config/param/ParamType.kt new file mode 100644 index 00000000..27c2a82b --- /dev/null +++ b/cache-550/src/main/kotlin/org/openrs2/cache/config/param/ParamType.kt @@ -0,0 +1,42 @@ +package org.openrs2.cache.config.param + +import io.netty.buffer.ByteBuf +import org.openrs2.buffer.readString +import org.openrs2.buffer.writeString +import org.openrs2.cache.config.ConfigType +import org.openrs2.util.charset.Cp1252Charset + +public class ParamType(id: Int) : ConfigType(id) { + public var type: Char = 0.toChar() + public var defaultInt: Int = 0 + public var defaultString: String? = null + + override fun read(buf: ByteBuf, code: Int) { + when (code) { + 1 -> type = Cp1252Charset.decode(buf.readByte()) + 2 -> defaultInt = buf.readInt() + 5 -> defaultString = buf.readString() + else -> throw IllegalArgumentException("Unsupported config code: $code") + } + } + + override fun write(buf: ByteBuf) { + if (type.code != 0) { + buf.writeByte(1) + buf.writeByte(Cp1252Charset.encode(type).toInt()) + } + + if (defaultInt != 0) { + buf.writeByte(2) + buf.writeInt(defaultInt) + } + + val defaultString = defaultString + if (defaultString != null) { + buf.writeByte(5) + buf.writeString(defaultString) + } + + buf.writeByte(0) + } +} diff --git a/cache-550/src/main/kotlin/org/openrs2/cache/config/param/ParamTypeList.kt b/cache-550/src/main/kotlin/org/openrs2/cache/config/param/ParamTypeList.kt new file mode 100644 index 00000000..b49062eb --- /dev/null +++ b/cache-550/src/main/kotlin/org/openrs2/cache/config/param/ParamTypeList.kt @@ -0,0 +1,16 @@ +package org.openrs2.cache.config.param + +import org.openrs2.cache.Cache +import org.openrs2.cache.Js5Archive +import org.openrs2.cache.Js5ConfigGroup +import org.openrs2.cache.config.GroupConfigTypeList + +public class ParamTypeList(cache: Cache) : GroupConfigTypeList( + cache, + archive = Js5Archive.CONFIG, + group = Js5ConfigGroup.PARAMTYPE +) { + override fun allocate(id: Int): ParamType { + return ParamType(id) + } +} diff --git a/cache-550/src/main/kotlin/org/openrs2/cache/config/struct/StructType.kt b/cache-550/src/main/kotlin/org/openrs2/cache/config/struct/StructType.kt new file mode 100644 index 00000000..cdc550eb --- /dev/null +++ b/cache-550/src/main/kotlin/org/openrs2/cache/config/struct/StructType.kt @@ -0,0 +1,57 @@ +package org.openrs2.cache.config.struct + +import io.netty.buffer.ByteBuf +import it.unimi.dsi.fastutil.ints.Int2ObjectMap +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap +import org.openrs2.buffer.readString +import org.openrs2.buffer.writeString +import org.openrs2.cache.config.ConfigType + +public class StructType(id: Int) : ConfigType(id) { + // TODO(gpe): methods for manipulating the map + private val params: Int2ObjectMap = Int2ObjectOpenHashMap() + + override fun read(buf: ByteBuf, code: Int) { + when (code) { + 249 -> { + val size = buf.readUnsignedByte().toInt() + for (i in 0 until size) { + val string = buf.readBoolean() + val id = buf.readUnsignedMedium() + + if (string) { + params[id] = buf.readString() + } else { + params[id] = buf.readInt() + } + } + } + else -> throw IllegalArgumentException("Unsupported config code: $code") + } + } + + override fun write(buf: ByteBuf) { + if (params.isNotEmpty()) { + buf.writeByte(249) + buf.writeByte(params.size) + + for ((id, value) in params.int2ObjectEntrySet()) { + when (value) { + is String -> { + buf.writeBoolean(true) + buf.writeMedium(id) + buf.writeString(value) + } + is Int -> { + buf.writeBoolean(false) + buf.writeMedium(id) + buf.writeInt(value) + } + else -> throw IllegalStateException() + } + } + } + + buf.writeByte(0) + } +} diff --git a/cache-550/src/main/kotlin/org/openrs2/cache/config/struct/StructTypeList.kt b/cache-550/src/main/kotlin/org/openrs2/cache/config/struct/StructTypeList.kt new file mode 100644 index 00000000..13574c52 --- /dev/null +++ b/cache-550/src/main/kotlin/org/openrs2/cache/config/struct/StructTypeList.kt @@ -0,0 +1,16 @@ +package org.openrs2.cache.config.struct + +import org.openrs2.cache.Cache +import org.openrs2.cache.Js5Archive +import org.openrs2.cache.Js5ConfigGroup +import org.openrs2.cache.config.GroupConfigTypeList + +public class StructTypeList(cache: Cache) : GroupConfigTypeList( + cache, + archive = Js5Archive.CONFIG, + group = Js5ConfigGroup.STRUCTTYPE +) { + override fun allocate(id: Int): StructType { + return StructType(id) + } +} diff --git a/cache-550/src/main/kotlin/org/openrs2/cache/config/varbit/VarbitType.kt b/cache-550/src/main/kotlin/org/openrs2/cache/config/varbit/VarbitType.kt new file mode 100644 index 00000000..e60d7ed8 --- /dev/null +++ b/cache-550/src/main/kotlin/org/openrs2/cache/config/varbit/VarbitType.kt @@ -0,0 +1,32 @@ +package org.openrs2.cache.config.varbit + +import io.netty.buffer.ByteBuf +import org.openrs2.cache.config.ConfigType + +public class VarbitType(id: Int) : ConfigType(id) { + public var baseVar: Int = 0 + public var startBit: Int = 0 + public var endBit: Int = 0 + + override fun read(buf: ByteBuf, code: Int) { + when (code) { + 1 -> { + baseVar = buf.readUnsignedShort() + startBit = buf.readUnsignedByte().toInt() + endBit = buf.readUnsignedByte().toInt() + } + else -> throw IllegalArgumentException("Unsupported config code: $code") + } + } + + override fun write(buf: ByteBuf) { + if (baseVar != 0 || startBit != 0 || endBit != 0) { + buf.writeByte(1) + buf.writeShort(baseVar) + buf.writeByte(startBit) + buf.writeByte(endBit) + } + + buf.writeByte(0) + } +} diff --git a/cache-550/src/main/kotlin/org/openrs2/cache/config/varbit/VarbitTypeList.kt b/cache-550/src/main/kotlin/org/openrs2/cache/config/varbit/VarbitTypeList.kt new file mode 100644 index 00000000..70d408db --- /dev/null +++ b/cache-550/src/main/kotlin/org/openrs2/cache/config/varbit/VarbitTypeList.kt @@ -0,0 +1,15 @@ +package org.openrs2.cache.config.varbit + +import org.openrs2.cache.Cache +import org.openrs2.cache.Js5Archive +import org.openrs2.cache.config.ArchiveConfigTypeList + +public class VarbitTypeList(cache: Cache) : ArchiveConfigTypeList( + cache, + archive = Js5Archive.CONFIG_VAR_BIT, + fileBits = 10 +) { + override fun allocate(id: Int): VarbitType { + return VarbitType(id) + } +} diff --git a/cache-550/src/main/kotlin/org/openrs2/cache/config/varp/VarpType.kt b/cache-550/src/main/kotlin/org/openrs2/cache/config/varp/VarpType.kt new file mode 100644 index 00000000..92695b05 --- /dev/null +++ b/cache-550/src/main/kotlin/org/openrs2/cache/config/varp/VarpType.kt @@ -0,0 +1,24 @@ +package org.openrs2.cache.config.varp + +import io.netty.buffer.ByteBuf +import org.openrs2.cache.config.ConfigType + +public class VarpType(id: Int) : ConfigType(id) { + public var clientCode: Int = 0 + + override fun read(buf: ByteBuf, code: Int) { + when (code) { + 5 -> clientCode = buf.readUnsignedShort() + else -> throw IllegalArgumentException("Unsupported config code: $code") + } + } + + override fun write(buf: ByteBuf) { + if (clientCode != 0) { + buf.writeByte(5) + buf.writeShort(clientCode) + } + + buf.writeByte(0) + } +} diff --git a/cache-550/src/main/kotlin/org/openrs2/cache/config/varp/VarpTypeList.kt b/cache-550/src/main/kotlin/org/openrs2/cache/config/varp/VarpTypeList.kt new file mode 100644 index 00000000..ecb3cd00 --- /dev/null +++ b/cache-550/src/main/kotlin/org/openrs2/cache/config/varp/VarpTypeList.kt @@ -0,0 +1,16 @@ +package org.openrs2.cache.config.varp + +import org.openrs2.cache.Cache +import org.openrs2.cache.Js5Archive +import org.openrs2.cache.Js5ConfigGroup +import org.openrs2.cache.config.GroupConfigTypeList + +public class VarpTypeList(cache: Cache) : GroupConfigTypeList( + cache, + archive = Js5Archive.CONFIG, + group = Js5ConfigGroup.VAR_PLAYER +) { + override fun allocate(id: Int): VarpType { + return VarpType(id) + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index b77cc734..e16b720d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -31,6 +31,7 @@ include( "buffer", "buffer-generator", "cache", + "cache-550", "cli", "compress", "compress-cli",