Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
747 B
36 lines
747 B
2 years ago
|
package org.openrs2.protocol.js5.downstream
|
||
4 years ago
|
|
||
|
import io.netty.buffer.ByteBuf
|
||
|
|
||
|
internal fun ByteBuf.xor(key: Int): ByteBuf {
|
||
|
if (key == 0) {
|
||
|
return retain()
|
||
|
}
|
||
|
|
||
|
val buf = if (refCnt() == 1) {
|
||
|
retain()
|
||
|
} else {
|
||
|
copy()
|
||
|
}
|
||
|
|
||
|
if (buf.hasArray()) {
|
||
|
val array = buf.array()
|
||
|
|
||
|
val off = buf.arrayOffset() + buf.readerIndex()
|
||
|
val len = buf.readableBytes()
|
||
|
|
||
|
for (i in off until off + len) {
|
||
|
array[i] = (array[i].toInt() xor key).toByte()
|
||
|
}
|
||
|
} else {
|
||
|
val off = buf.readerIndex()
|
||
|
val len = buf.readableBytes()
|
||
|
|
||
|
for (i in off until off + len) {
|
||
|
buf.setByte(i, buf.getByte(i).toInt() xor key)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return buf
|
||
|
}
|