Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision 225 #28

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package net.rsprox.protocol.game.outgoing.decoder.codec.inv

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.metadata.Consistent
import net.rsprox.protocol.ProxyMessageDecoder
import net.rsprox.protocol.game.outgoing.decoder.prot.GameServerProt
import net.rsprox.protocol.game.outgoing.model.inv.UpdateInvStopTransmit
import net.rsprox.protocol.session.Session

@Consistent
public class UpdateInvStopTransmitDecoder : ProxyMessageDecoder<UpdateInvStopTransmit> {
override val prot: ClientProt = GameServerProt.UPDATE_INV_STOPTRANSMIT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package net.rsprox.protocol.game.outgoing.decoder.codec.inv

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.metadata.Consistent
import net.rsprox.protocol.ProxyMessageDecoder
import net.rsprox.protocol.game.outgoing.decoder.prot.GameServerProt
import net.rsprox.protocol.game.outgoing.model.inv.UpdateInvStopTransmit
import net.rsprox.protocol.session.Session

@Consistent
public class UpdateInvStopTransmitDecoder : ProxyMessageDecoder<UpdateInvStopTransmit> {
override val prot: ClientProt = GameServerProt.UPDATE_INV_STOPTRANSMIT

Expand Down
14 changes: 14 additions & 0 deletions protocol/osrs-225/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dependencies {
implementation(platform(rootProject.libs.netty.bom))
implementation(rootProject.libs.netty.buffer)
implementation(rootProject.libs.netty.transport)
implementation(rootProject.libs.netty.handler)
implementation(rootProject.libs.rsprot.buffer)
implementation(rootProject.libs.rsprot.compression)
implementation(rootProject.libs.rsprot.protocol)
implementation(rootProject.libs.rsprot.crypto)
implementation(platform(rootProject.libs.log4j.bom))
implementation(rootProject.libs.bundles.log4j)
implementation(projects.protocol)
implementation(projects.cache.cacheApi)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.rsprox.protocol

import net.rsprot.buffer.JagByteBuf
import net.rsprot.compression.HuffmanCodec
import net.rsprot.protocol.message.IncomingMessage
import net.rsprox.protocol.game.incoming.decoder.prot.ClientMessageDecoderRepository
import net.rsprox.protocol.session.Session

public class ClientPacketDecoderService(
huffmanCodec: HuffmanCodec,
) : ClientPacketDecoder {
@OptIn(ExperimentalStdlibApi::class)
private val repository = ClientMessageDecoderRepository.build(huffmanCodec)

override fun decode(
opcode: Int,
payload: JagByteBuf,
session: Session,
): IncomingMessage {
return repository
.getDecoder(opcode)
.decode(payload, session)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.rsprox.protocol

import net.rsprox.protocol.game.incoming.decoder.prot.GameClientProt

public data object GameClientProtProvider : ProtProvider<GameClientProt> {
override fun get(opcode: Int): GameClientProt {
return GameClientProt.entries.firstOrNull { it.opcode == opcode }
?: throw IllegalArgumentException("Unknown game client prot: $opcode")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.rsprox.protocol

import net.rsprox.protocol.game.outgoing.decoder.prot.GameServerProt

public data object GameServerProtProvider : ProtProvider<GameServerProt> {
override fun get(opcode: Int): GameServerProt {
return GameServerProt.entries.firstOrNull { it.opcode == opcode }
?: throw IllegalArgumentException("Unknown game server prot: $opcode")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.rsprox.protocol

import net.rsprot.buffer.JagByteBuf
import net.rsprot.compression.HuffmanCodec
import net.rsprot.protocol.message.IncomingMessage
import net.rsprox.cache.api.CacheProvider
import net.rsprox.protocol.game.outgoing.decoder.prot.ServerMessageDecoderRepository
import net.rsprox.protocol.session.Session

public class ServerPacketDecoderService(
huffmanCodec: HuffmanCodec,
cache: CacheProvider,
) : ServerPacketDecoder {
@OptIn(ExperimentalStdlibApi::class)
private val repository =
ServerMessageDecoderRepository.build(
huffmanCodec,
cache,
)

override fun decode(
opcode: Int,
payload: JagByteBuf,
session: Session,
): IncomingMessage {
return repository
.getDecoder(opcode)
.decode(payload, session)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package net.rsprox.protocol.common

/**
* Coord grid, commonly referred to just as Coordinate or Location,
* is responsible for tracking absolute positions of avatars in the game.
* @param packed the 30-bit bitpacked integer representing the coord grid.
*/
@JvmInline
public value class CoordGrid(
public val packed: Int,
) {
/**
* @param level the height level of the avatar.
* @param x the absolute x coordinate of the avatar.
* @param z the absolute z coordinate of the avatar.
*/
@Suppress("ConvertTwoComparisonsToRangeCheck")
public constructor(
level: Int,
x: Int,
z: Int,
) : this(
(level shl 28)
.or(x shl 14)
.or(z),
) {
// https://youtrack.jetbrains.com/issue/KT-62798/in-range-checks-are-not-intrinsified-in-kotlin-stdlib
// Using traditional checks to avoid generating range objects (seen by decompiling this class)
require(level >= 0 && level < 4) {
"Level must be in range of 0..<4: $level"
}
require(x >= 0 && x <= 16384) {
"X coordinate must be in range of 0..<16384: $x"
}
require(z >= 0 && z <= 16384) {
"Z coordinate must be in range of 0..<16384, $z"
}
}

public val level: Int
get() = packed ushr 28
public val x: Int
get() = packed ushr 14 and 0x3FFF
public val z: Int
get() = packed and 0x3FFF

/**
* Checks whether this coord grid is within [distance] of the [other] coord grid.
* If the coord grids are on different levels, this function will always return false.
* @param other the other coord grid to check against.
* @param distance the distance to check (inclusive). A distance of 0 implies same coordinate.
* @return true if the [other] coord grid is within [distance] of this coord grid.
*/
public fun inDistance(
other: CoordGrid,
distance: Int,
): Boolean {
if (level != other.level) {
return false
}
val deltaX = x - other.x
if (deltaX !in -distance..distance) {
return false
}
val deltaZ = z - other.z
return deltaZ in -distance..distance
}

/**
* Checks if this coord grid is uninitialized.
* Uninitialized coord grids are determined by checking if all 32 bits of
* the [packed] property are enabled (including sign bit, which would be the opposite).
* As the main constructor of this class only takes in the components that build a coord grid,
* it is impossible to make an instance of this that matches the invalid value,
* unless directly using the single-argument constructor.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun invalid(): Boolean {
return this == INVALID
}

public operator fun component1(): Int {
return level
}

public operator fun component2(): Int {
return x
}

public operator fun component3(): Int {
return z
}

override fun toString(): String {
return "CoordGrid(" +
"level=$level, " +
"x=$x, " +
"z=$z" +
")"
}

public companion object {
public val INVALID: CoordGrid = CoordGrid(-1)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.rsprox.protocol.common

public object OldSchoolZoneProt {
public const val LOC_ADD_CHANGE: Int = 0
public const val LOC_DEL: Int = 1
public const val LOC_ANIM: Int = 2
public const val LOC_MERGE: Int = 3
public const val OBJ_ADD: Int = 4
public const val OBJ_DEL: Int = 5
public const val OBJ_COUNT: Int = 6
public const val OBJ_ENABLED_OPS: Int = 7
public const val MAP_ANIM: Int = 8
public const val MAP_PROJANIM: Int = 9
public const val SOUND_AREA: Int = 10
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.rsprox.protocol.game.incoming.decoder.codec.buttons

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.metadata.Consistent
import net.rsprot.protocol.util.gCombinedId
import net.rsprox.protocol.ProxyMessageDecoder
import net.rsprox.protocol.game.incoming.decoder.prot.GameClientProt
import net.rsprox.protocol.game.incoming.model.buttons.If1Button
import net.rsprox.protocol.session.Session

@Consistent
public class If1ButtonDecoder : ProxyMessageDecoder<If1Button> {
override val prot: ClientProt = GameClientProt.IF_BUTTON

override fun decode(
buffer: JagByteBuf,
session: Session,
): If1Button {
val combinedId = buffer.gCombinedId()
return If1Button(combinedId)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.rsprox.protocol.game.incoming.decoder.codec.buttons

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.metadata.Consistent
import net.rsprot.protocol.util.gCombinedId
import net.rsprox.protocol.ProxyMessageDecoder
import net.rsprox.protocol.game.incoming.decoder.prot.GameClientProt
import net.rsprox.protocol.game.incoming.model.buttons.If3Button
import net.rsprox.protocol.session.Session

@Consistent
public class If3ButtonDecoder(
override val prot: GameClientProt,
private val op: Int,
) : ProxyMessageDecoder<If3Button> {
override fun decode(
buffer: JagByteBuf,
session: Session,
): If3Button {
val combinedId = buffer.gCombinedId()
val sub = buffer.g2()
val obj = buffer.g2()
return If3Button(
combinedId,
sub,
obj,
op,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.rsprox.protocol.game.incoming.decoder.codec.buttons

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.util.gCombinedIdAlt1
import net.rsprox.protocol.ProxyMessageDecoder
import net.rsprox.protocol.game.incoming.decoder.prot.GameClientProt
import net.rsprox.protocol.game.incoming.model.buttons.IfButtonD
import net.rsprox.protocol.session.Session

public class IfButtonDDecoder : ProxyMessageDecoder<IfButtonD> {
override val prot: ClientProt = GameClientProt.IF_BUTTOND

override fun decode(
buffer: JagByteBuf,
session: Session,
): IfButtonD {
val selectedCombinedId = buffer.gCombinedIdAlt1()
val selectedObj = buffer.g2Alt1()
val selectedSub = buffer.g2Alt2()
val targetObj = buffer.g2()
val targetSub = buffer.g2Alt1()
val targetCombinedId = buffer.gCombinedIdAlt1()
return IfButtonD(
selectedCombinedId,
selectedSub,
selectedObj,
targetCombinedId,
targetSub,
targetObj,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.rsprox.protocol.game.incoming.decoder.codec.buttons

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.util.gCombinedIdAlt2
import net.rsprot.protocol.util.gCombinedIdAlt3
import net.rsprox.protocol.ProxyMessageDecoder
import net.rsprox.protocol.game.incoming.decoder.prot.GameClientProt
import net.rsprox.protocol.game.incoming.model.buttons.IfButtonT
import net.rsprox.protocol.session.Session

public class IfButtonTDecoder : ProxyMessageDecoder<IfButtonT> {
override val prot: ClientProt = GameClientProt.IF_BUTTONT

override fun decode(
buffer: JagByteBuf,
session: Session,
): IfButtonT {
val targetSub = buffer.g2Alt3()
val selectedCombinedId = buffer.gCombinedIdAlt2()
val targetObj = buffer.g2Alt3()
val selectedSub = buffer.g2Alt3()
val selectedObj = buffer.g2Alt1()
val targetCombinedId = buffer.gCombinedIdAlt3()
return IfButtonT(
selectedCombinedId,
selectedSub,
selectedObj,
targetCombinedId,
targetSub,
targetObj,
)
}
}
Loading