forked from openrs2/openrs2
Signed-off-by: Graham <gpe@openrs2.org>bzip2
parent
21cf2526c5
commit
849b083400
@ -0,0 +1,28 @@ |
||||
plugins { |
||||
`maven-publish` |
||||
kotlin("jvm") |
||||
} |
||||
|
||||
dependencies { |
||||
api(projects.cache) |
||||
|
||||
implementation(projects.buffer) |
||||
implementation(projects.util) |
||||
} |
||||
|
||||
publishing { |
||||
publications.create<MavenPublication>("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() |
||||
) |
||||
} |
||||
} |
||||
} |
@ -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<String>? = 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<String>() |
||||
|
||||
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) |
||||
} |
||||
} |
@ -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<EnumType>( |
||||
cache, |
||||
archive = Js5Archive.CONFIG_ENUM, |
||||
fileBits = 8 |
||||
) { |
||||
override fun allocate(id: Int): EnumType { |
||||
return EnumType(id) |
||||
} |
||||
} |
@ -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) |
||||
} |
||||
} |
@ -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<ParamType>( |
||||
cache, |
||||
archive = Js5Archive.CONFIG, |
||||
group = Js5ConfigGroup.PARAMTYPE |
||||
) { |
||||
override fun allocate(id: Int): ParamType { |
||||
return ParamType(id) |
||||
} |
||||
} |
@ -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<Any> = 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) |
||||
} |
||||
} |
@ -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<StructType>( |
||||
cache, |
||||
archive = Js5Archive.CONFIG, |
||||
group = Js5ConfigGroup.STRUCTTYPE |
||||
) { |
||||
override fun allocate(id: Int): StructType { |
||||
return StructType(id) |
||||
} |
||||
} |
@ -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) |
||||
} |
||||
} |
@ -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<VarbitType>( |
||||
cache, |
||||
archive = Js5Archive.CONFIG_VAR_BIT, |
||||
fileBits = 10 |
||||
) { |
||||
override fun allocate(id: Int): VarbitType { |
||||
return VarbitType(id) |
||||
} |
||||
} |
@ -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) |
||||
} |
||||
} |
@ -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<VarpType>( |
||||
cache, |
||||
archive = Js5Archive.CONFIG, |
||||
group = Js5ConfigGroup.VAR_PLAYER |
||||
) { |
||||
override fun allocate(id: Int): VarpType { |
||||
return VarpType(id) |
||||
} |
||||
} |
Loading…
Reference in new issue