Skip to content

Commit

Permalink
Pre 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Newspicel committed Jan 9, 2023
1 parent c258495 commit 38bfc4b
Show file tree
Hide file tree
Showing 175 changed files with 7,098 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.8.0"
id("org.jetbrains.dokka") version "1.7.10"
id("org.jetbrains.dokka") version "1.7.20"
`maven-publish`
}

Expand Down
10 changes: 7 additions & 3 deletions scripts/packet_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
src = "src/main/kotlin"

wikivg_url = "https://wiki.vg/index.php?title=Protocol"
wikivg_url_end = "&oldid=17873"
wikivg_url_end = "&oldid=17932"
wikivg_text = requests.get(wikivg_url + wikivg_url_end).text

data_url = "https://raw.githubusercontent.com/PrismarineJS/minecraft-data/master/data/pc/1.19.2/protocol.json"
data_url = "https://raw.githubusercontent.com/Layercraft/minecraft-data/master/data/pc/1.19.3/protocol.json"

version = data_url.split("/")[-2]
version_underline = version.replace(".", "_")
Expand Down Expand Up @@ -230,7 +230,11 @@ def generate(self) -> str:

print(f"Generate: {self.package}.{self.class_name} ({self.id})")

fields = self.generate_fields()
try :
fields = self.generate_fields()
except Exception as e:
print(f"Error: {self.package}.{self.class_name} ({self.id})")
return "//TODO"

class_fields_str = fields["class_fields_str"]
class_serialize_str = fields["class_serialize_str"]
Expand Down
185 changes: 185 additions & 0 deletions src/main/kotlin/io/layercraft/packetlib/codec/MinecraftCodecs.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.layercraft.packetlib.packets.v1_19_3.handshaking.serverbound

import io.layercraft.packetlib.packets.*
import io.layercraft.packetlib.serialization.MinecraftProtocolDeserializeInterface
import io.layercraft.packetlib.serialization.MinecraftProtocolSerializeInterface

/**
* Legacy Server List Ping | 0xfe | handshaking | serverbound
*
* @param payload payload
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=17932#Legacy_Server_List_Ping">https://wiki.vg/Protocol#Legacy_Server_List_Ping</a>
*/

@MinecraftPacket(id = 0xfe, state = PacketState.HANDSHAKING, direction = PacketDirection.SERVERBOUND)
data class LegacyServerListPingPacket(
val payload: UByte,
) : ServerBoundPacket {
companion object : PacketSerializer<LegacyServerListPingPacket> {
override fun deserialize(input: MinecraftProtocolDeserializeInterface<*>): LegacyServerListPingPacket {
val payload = input.readUByte()

return LegacyServerListPingPacket(payload)
}

override fun serialize(output: MinecraftProtocolSerializeInterface<*>, value: LegacyServerListPingPacket) {
output.writeUByte(value.payload)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.layercraft.packetlib.packets.v1_19_3.handshaking.serverbound

import io.layercraft.packetlib.packets.*
import io.layercraft.packetlib.serialization.MinecraftProtocolDeserializeInterface
import io.layercraft.packetlib.serialization.MinecraftProtocolSerializeInterface

/**
* Handshake | 0x00 | handshaking | serverbound
*
* @param protocolVersion protocolVersion
* @param serverHost serverHost
* @param serverPort serverPort
* @param nextState nextState
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=17932#Handshake">https://wiki.vg/Protocol#Handshake</a>
*/

@MinecraftPacket(id = 0x00, state = PacketState.HANDSHAKING, direction = PacketDirection.SERVERBOUND)
data class SetProtocolPacket(
val protocolVersion: Int, // varint
val serverHost: String,
val serverPort: UShort,
val nextState: Int, // varint
) : ServerBoundPacket {
companion object : PacketSerializer<SetProtocolPacket> {
override fun deserialize(input: MinecraftProtocolDeserializeInterface<*>): SetProtocolPacket {
val protocolVersion = input.readVarInt()
val serverHost = input.readString()
val serverPort = input.readUShort()
val nextState = input.readVarInt()

return SetProtocolPacket(protocolVersion, serverHost, serverPort, nextState)
}

override fun serialize(output: MinecraftProtocolSerializeInterface<*>, value: SetProtocolPacket) {
output.writeVarInt(value.protocolVersion)
output.writeString(value.serverHost)
output.writeUShort(value.serverPort)
output.writeVarInt(value.nextState)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.layercraft.packetlib.packets.v1_19_3.login.clientbound

import io.layercraft.packetlib.packets.*
import io.layercraft.packetlib.serialization.MinecraftProtocolDeserializeInterface
import io.layercraft.packetlib.serialization.MinecraftProtocolSerializeInterface

/**
* Set Compression | 0x03 | login | clientbound
*
* @param threshold threshold
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=17932#Set_Compression">https://wiki.vg/Protocol#Set_Compression</a>
*/

@MinecraftPacket(id = 0x03, state = PacketState.LOGIN, direction = PacketDirection.CLIENTBOUND)
data class CompressPacket(
val threshold: Int, // varint
) : ClientBoundPacket {
companion object : PacketSerializer<CompressPacket> {
override fun deserialize(input: MinecraftProtocolDeserializeInterface<*>): CompressPacket {
val threshold = input.readVarInt()

return CompressPacket(threshold)
}

override fun serialize(output: MinecraftProtocolSerializeInterface<*>, value: CompressPacket) {
output.writeVarInt(value.threshold)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.layercraft.packetlib.packets.v1_19_3.login.clientbound

import io.layercraft.packetlib.packets.*
import io.layercraft.packetlib.serialization.MinecraftProtocolDeserializeInterface
import io.layercraft.packetlib.serialization.MinecraftProtocolSerializeInterface

/**
* Disconnect (login) | 0x00 | login | clientbound
*
* @param reason reason
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=17932#Disconnect_.28login.29">https://wiki.vg/Protocol#Disconnect_.28login.29</a>
*/

@MinecraftPacket(id = 0x00, state = PacketState.LOGIN, direction = PacketDirection.CLIENTBOUND)
data class DisconnectPacket(
val reason: String,
) : ClientBoundPacket {
companion object : PacketSerializer<DisconnectPacket> {
override fun deserialize(input: MinecraftProtocolDeserializeInterface<*>): DisconnectPacket {
val reason = input.readString()

return DisconnectPacket(reason)
}

override fun serialize(output: MinecraftProtocolSerializeInterface<*>, value: DisconnectPacket) {
output.writeString(value.reason)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.layercraft.packetlib.packets.v1_19_3.login.clientbound

import io.layercraft.packetlib.packets.*
import io.layercraft.packetlib.serialization.MinecraftProtocolDeserializeInterface
import io.layercraft.packetlib.serialization.MinecraftProtocolSerializeInterface

/**
* Encryption Request | 0x01 | login | clientbound
*
* @param serverId serverId
* @param publicKey publicKey
* @param verifyToken verifyToken
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=17932#Encryption_Request">https://wiki.vg/Protocol#Encryption_Request</a>
*/

@MinecraftPacket(id = 0x01, state = PacketState.LOGIN, direction = PacketDirection.CLIENTBOUND)
data class EncryptionBeginPacket(
val serverId: String,
val publicKey: ByteArray,
val verifyToken: ByteArray,
) : ClientBoundPacket {
companion object : PacketSerializer<EncryptionBeginPacket> {
override fun deserialize(input: MinecraftProtocolDeserializeInterface<*>): EncryptionBeginPacket {
val serverId = input.readString()
val publicKey = input.readVarIntByteArray()
val verifyToken = input.readVarIntByteArray()

return EncryptionBeginPacket(serverId, publicKey, verifyToken)
}

override fun serialize(output: MinecraftProtocolSerializeInterface<*>, value: EncryptionBeginPacket) {
output.writeString(value.serverId)
output.writeVarIntByteArray(value.publicKey)
output.writeVarIntByteArray(value.verifyToken)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.layercraft.packetlib.packets.v1_19_3.login.clientbound

import io.layercraft.packetlib.packets.*
import io.layercraft.packetlib.serialization.MinecraftProtocolDeserializeInterface
import io.layercraft.packetlib.serialization.MinecraftProtocolSerializeInterface

/**
* Login Plugin Request | 0x04 | login | clientbound
*
* @param messageId messageId
* @param channel channel
* @param data data
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=17932#Login_Plugin_Request">https://wiki.vg/Protocol#Login_Plugin_Request</a>
*/

@MinecraftPacket(id = 0x04, state = PacketState.LOGIN, direction = PacketDirection.CLIENTBOUND)
data class LoginPluginRequestPacket(
val messageId: Int, // varint
val channel: String,
val data: ByteArray,
) : ClientBoundPacket {
companion object : PacketSerializer<LoginPluginRequestPacket> {
override fun deserialize(input: MinecraftProtocolDeserializeInterface<*>): LoginPluginRequestPacket {
val messageId = input.readVarInt()
val channel = input.readString()
val data = input.readRemainingByteArray()

return LoginPluginRequestPacket(messageId, channel, data)
}

override fun serialize(output: MinecraftProtocolSerializeInterface<*>, value: LoginPluginRequestPacket) {
output.writeVarInt(value.messageId)
output.writeString(value.channel)
output.writeRemainingByteArray(value.data)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.layercraft.packetlib.packets.v1_19_3.login.clientbound

import io.layercraft.packetlib.packets.*
import io.layercraft.packetlib.serialization.MinecraftProtocolDeserializeInterface
import io.layercraft.packetlib.serialization.MinecraftProtocolSerializeInterface
import java.util.UUID
/**
* Login Success | 0x02 | login | clientbound
*
* @param uuid uuid
* @param username username
* @param properties list of SuccessPacketProperties
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=17932#Login_Success">https://wiki.vg/Protocol#Login_Success</a>
*/

@MinecraftPacket(id = 0x02, state = PacketState.LOGIN, direction = PacketDirection.CLIENTBOUND)
data class SuccessPacket(
val uuid: UUID,
val username: String,
val properties: List<SuccessPacketProperties>, // varint array
) : ClientBoundPacket {
companion object : PacketSerializer<SuccessPacket> {
override fun deserialize(input: MinecraftProtocolDeserializeInterface<*>): SuccessPacket {
val uuid = input.readUUID()
val username = input.readString()
val properties = input.readVarIntArray { arrayInput ->
val name = arrayInput.readString()
val value = arrayInput.readString()
val hasSignature = arrayInput.readBoolean()
val signature = if (hasSignature) arrayInput.readString() else null

return@readVarIntArray SuccessPacketProperties(name, value, hasSignature, signature)
}

return SuccessPacket(uuid, username, properties)
}

override fun serialize(output: MinecraftProtocolSerializeInterface<*>, value: SuccessPacket) {
output.writeUUID(value.uuid)
output.writeString(value.username)

output.writeVarIntArray(value.properties) { arrayValue, arrayOutput ->
arrayOutput.writeString(arrayValue.name)
arrayOutput.writeString(arrayValue.value)
arrayOutput.writeBoolean(arrayValue.hasSignature)
if (arrayValue.hasSignature) arrayOutput.writeString(arrayValue.signature!!)
}
}
}
}

/**
* SuccessPacketProperties
*
* @param name name
* @param value value
* @param hasSignature signature is present
* @param signature signature
*/
data class SuccessPacketProperties(
val name: String,
val value: String,
val hasSignature: Boolean,
val signature: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.layercraft.packetlib.packets.v1_19_3.login.serverbound

import io.layercraft.packetlib.packets.*
import io.layercraft.packetlib.serialization.MinecraftProtocolDeserializeInterface
import io.layercraft.packetlib.serialization.MinecraftProtocolSerializeInterface

/**
* Encryption Response | 0x01 | login | serverbound
*
* @param sharedSecret sharedSecret
* @param verifyToken verifyToken
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=17932#Encryption_Response">https://wiki.vg/Protocol#Encryption_Response</a>
*/

@MinecraftPacket(id = 0x01, state = PacketState.LOGIN, direction = PacketDirection.SERVERBOUND)
data class EncryptionBeginPacket(
val sharedSecret: ByteArray,
val verifyToken: ByteArray,
) : ServerBoundPacket {
companion object : PacketSerializer<EncryptionBeginPacket> {
override fun deserialize(input: MinecraftProtocolDeserializeInterface<*>): EncryptionBeginPacket {
val sharedSecret = input.readVarIntByteArray()
val verifyToken = input.readVarIntByteArray()

return EncryptionBeginPacket(sharedSecret, verifyToken)
}

override fun serialize(output: MinecraftProtocolSerializeInterface<*>, value: EncryptionBeginPacket) {
output.writeVarIntByteArray(value.sharedSecret)
output.writeVarIntByteArray(value.verifyToken)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.layercraft.packetlib.packets.v1_19_3.login.serverbound

import io.layercraft.packetlib.packets.*
import io.layercraft.packetlib.serialization.MinecraftProtocolDeserializeInterface
import io.layercraft.packetlib.serialization.MinecraftProtocolSerializeInterface

/**
* Login Plugin Response | 0x02 | login | serverbound
*
* @param messageId messageId
* @param successful successful
* @param hasData data is present
* @param data data
* @see <a href="https://wiki.vg/index.php?title=Protocol&oldid=17932#Login_Plugin_Response">https://wiki.vg/Protocol#Login_Plugin_Response</a>
*/

@MinecraftPacket(id = 0x02, state = PacketState.LOGIN, direction = PacketDirection.SERVERBOUND)
data class LoginPluginResponsePacket(
val messageId: Int, // varint
val successful: Boolean,
val hasData: Boolean,
val data: ByteArray?,
) : ServerBoundPacket {
companion object : PacketSerializer<LoginPluginResponsePacket> {
override fun deserialize(input: MinecraftProtocolDeserializeInterface<*>): LoginPluginResponsePacket {
val messageId = input.readVarInt()
val successful = input.readBoolean()
val hasData = input.readBoolean()
val data = if (hasData) input.readRemainingByteArray() else null

return LoginPluginResponsePacket(messageId, successful, hasData, data)
}

override fun serialize(output: MinecraftProtocolSerializeInterface<*>, value: LoginPluginResponsePacket) {
output.writeVarInt(value.messageId)
output.writeBoolean(value.successful)
output.writeBoolean(value.hasData)
if (value.hasData) output.writeRemainingByteArray(value.data!!)
}
}
}
Loading

0 comments on commit 38bfc4b

Please sign in to comment.