summaryrefslogtreecommitdiff
path: root/packets
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-11-28 18:38:42 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-11-28 18:38:42 +0100
commite8aa9f50886b66d525307a58d71036e6fd3d4aa1 (patch)
treece6f59eecf1eb3e1ba2794166c09623d8a2d7d83 /packets
parentc89f25f59aa493d95bcac8e75ca5cdd57a0403e7 (diff)
next commit
Diffstat (limited to 'packets')
-rw-r--r--packets/character_information.gd246
-rw-r--r--packets/character_selection_success_packet.gd53
-rw-r--r--packets/character_server_information.gd70
-rw-r--r--packets/character_server_login_packet.gd12
-rw-r--r--packets/login_server_login_packet.gd14
-rw-r--r--packets/login_server_login_success_packet.gd25
-rw-r--r--packets/map_server_login_packet.gd13
-rw-r--r--packets/map_server_login_success_packet.gd48
-rw-r--r--packets/packet.gd23
-rw-r--r--packets/packet_chunk.gd10
-rw-r--r--packets/request_character_list_packet.gd7
-rw-r--r--packets/request_character_list_success_packet.gd3
-rw-r--r--packets/select_character_packet.gd18
13 files changed, 518 insertions, 24 deletions
diff --git a/packets/character_information.gd b/packets/character_information.gd
new file mode 100644
index 0000000..20e40cd
--- /dev/null
+++ b/packets/character_information.gd
@@ -0,0 +1,246 @@
+class_name CharacterInformation
+extends PacketChunk
+
+
+## Byte Type: u32
+## Byte Length: 4
+var character_id: int
+
+## Byte Type: i64
+## Byte Length: 8
+var experience: int
+
+## Byte Type: i32
+## Byte Length: 4
+var money: int
+
+## Byte Type: i64
+## Byte Length: 8
+var job_experience: int
+
+## Byte Type: i32
+## Byte Length: 4
+var job_level: int
+
+## Byte Type: i32
+## Byte Length: 4
+var body_state: int
+
+## Byte Type: i32
+## Byte Length: 4
+var health_state: int
+
+## Byte Type: i32
+## Byte Length: 4
+var effect_state: int
+
+## Byte Type: i32
+## Byte Length: 4
+var virtue: int
+
+## Byte Type: i32
+## Byte Length: 4
+var honor: int
+
+## Byte Type: i16
+## Byte Length: 2
+var jobpoint: int
+
+## Byte Type: i64
+## Byte Length: 8
+var health_points: int
+
+## Byte Type: i64
+## Byte Length: 8
+var maximum_health_points: int
+
+## Byte Type: i64
+## Byte Length: 8
+var spell_points: int
+
+## Byte Type: i64
+## Byte Length: 8
+var maximum_spell_points: int
+
+## Byte Type: i16
+## Byte Length: 2
+var movement_speed: int
+
+## Byte Type: i16
+## Byte Length: 2
+var job: int
+
+## Byte Type: i16
+## Byte Length: 2
+var head: int
+
+## Byte Type: i16
+## Byte Length: 2
+var body: int
+
+## Byte Type: i16
+## Byte Length: 2
+var weapon: int
+
+## Byte Type: i16
+## Byte Length: 2
+var level: int
+
+## Byte Type: i16
+## Byte Length: 2
+var skill_point: int
+
+## Byte Type: i16
+## Byte Length: 2
+var accessory: int
+
+## Byte Type: i16
+## Byte Length: 2
+var shield: int
+
+## Byte Type: i16
+## Byte Length: 2
+var accessory2: int
+
+## Byte Type: i16
+## Byte Length: 2
+var accessory3: int
+
+## Byte Type: i16
+## Byte Length: 2
+var head_palette: int
+
+## Byte Type: i16
+## Byte Length: 2
+var body_palette: int
+
+## Byte Type: u8
+## Byte Length: 24
+var name: String
+
+## Byte Type: u8
+## Byte Length: 1
+var strength: int
+
+## Byte Type: u8
+## Byte Length: 1
+var agility: int
+
+## Byte Type: u8
+## Byte Length: 1
+var vitality: int
+
+## Byte Type: u8
+## Byte Length: 1
+var intelligence: int
+
+## Byte Type: u8
+## Byte Length: 1
+var dexterity: int
+
+## Byte Type: u8
+## Byte Length: 1
+var luck: int
+
+## Byte Type: u8
+## Byte Length: 1
+var character_number: int
+
+## Byte Type: u8
+## Byte Length: 1
+var hair_color: int
+
+## Byte Type: i16
+## Byte Length: 2
+var b_is_changed_char: int
+
+## Byte Type: u8
+## Byte Length: 16
+var map_name: String
+
+## Byte Type: i32
+## Byte Length: 4
+var deletion_reverse_date: int
+
+## Byte Type: i32
+## Byte Length: 4
+var robe_palette: int
+
+## Byte Type: i32
+## Byte Length: 4
+var character_slot_change: int
+
+## Byte Type: i32
+## Byte Length: 4
+var character_name_change: int
+
+## Byte Type: u8
+## Byte Length: 1
+var gender: Constants.Gender
+
+
+func _init() -> void:
+ byte_length = 175
+
+
+static func from_bytes(bytes: PackedByteArray):
+ var info = CharacterInformation.new()
+
+ info.character_id = bytes.decode_u32(0)
+ info.experience = bytes.decode_s64(4)
+ info.money = bytes.decode_s32(12)
+ info.job_experience = bytes.decode_s64(16)
+ info.job_level = bytes.decode_s32(24)
+ info.body_state = bytes.decode_s32(28)
+ info.health_state = bytes.decode_s32(32)
+ info.effect_state = bytes.decode_s32(36)
+ info.virtue = bytes.decode_s32(40)
+ info.honor = bytes.decode_s32(44)
+ info.jobpoint = bytes.decode_s16(48)
+ info.health_points = bytes.decode_s64(50)
+ info.maximum_health_points = bytes.decode_s64(58)
+ info.spell_points = bytes.decode_s64(66)
+ info.maximum_spell_points = bytes.decode_s64(74)
+ info.movement_speed = bytes.decode_s16(82)
+ info.job = bytes.decode_s16(84)
+ info.head = bytes.decode_s16(86)
+ info.body = bytes.decode_s16(88)
+ info.weapon = bytes.decode_s16(90)
+ info.level = bytes.decode_s16(92)
+ info.skill_point = bytes.decode_s16(94)
+ info.accessory = bytes.decode_s16(96)
+ info.shield = bytes.decode_s16(98)
+ info.accessory2 = bytes.decode_s16(100)
+ info.accessory3 = bytes.decode_s16(102)
+ info.head_palette = bytes.decode_s16(104)
+ info.body_palette = bytes.decode_s16(106)
+ info.name = bytes.slice(108, 108 + 24).get_string_from_utf8()
+ info.strength = bytes.decode_u8(132)
+ info.agility = bytes.decode_u8(133)
+ info.vitality = bytes.decode_u8(134)
+ info.intelligence = bytes.decode_u8(135)
+ info.dexterity = bytes.decode_u8(136)
+ info.luck = bytes.decode_u8(137)
+ info.character_number = bytes.decode_u8(138)
+ info.hair_color = bytes.decode_u8(139)
+ info.b_is_changed_char = bytes.decode_s16(140)
+ info.map_name = bytes.slice(142, 142 + 16).get_string_from_utf8()
+ info.deletion_reverse_date = bytes.decode_s32(158)
+ info.robe_palette = bytes.decode_s32(162)
+ info.character_slot_change = bytes.decode_s32(166)
+ info.character_name_change = bytes.decode_s32(170)
+ info.gender = bytes.decode_u8(174)
+
+ return info
+
+
+static func array_from_bytes(bytes: PackedByteArray) -> Array:
+ var array = []
+
+ var offset = 0
+ while offset < bytes.size():
+ var chunk = from_bytes(bytes.slice(offset))
+ array.append(chunk)
+ offset += chunk.byte_length
+
+ return array
diff --git a/packets/character_selection_success_packet.gd b/packets/character_selection_success_packet.gd
new file mode 100644
index 0000000..f483d9e
--- /dev/null
+++ b/packets/character_selection_success_packet.gd
@@ -0,0 +1,53 @@
+class_name CharacterSelectionSuccessPacket
+extends Packet
+
+
+static var header := 0x0ac5
+
+
+## Byte Type: u32
+## Byte Length: 4
+var character_id: int
+
+## Byte Type: u8
+## Byte Length: 16
+var map_name: String
+
+## Byte Type: u32
+## Byte Length: 4
+var map_server_ip: PackedByteArray
+
+## Byte Type: u16
+## Byte Length: 2
+var map_server_port: int
+
+## Byte Type: u8
+## Byte Length: 128
+var unknown: PackedByteArray
+
+
+func get_map_server_ip():
+ return "%s.%s.%s.%s" % [
+ map_server_ip.decode_u8(0),
+ map_server_ip.decode_u8(1),
+ map_server_ip.decode_u8(2),
+ map_server_ip.decode_u8(3)
+ ]
+
+
+static func from_bytes(bytes: PackedByteArray):
+ var packet = CharacterSelectionSuccessPacket.new()
+
+ packet.character_id = bytes.decode_u32(0)
+ packet.map_name = bytes.slice(4, 4 + 16).get_string_from_utf8()
+ packet.map_server_ip = bytes.slice(20, 20 + 4)
+ packet.map_server_port = bytes.decode_u16(24)
+ packet.unknown = bytes.slice(26)
+
+ return packet
+
+static func from_bytes_via_peer(peer: StreamPeer):
+ var _header = peer.get_data(2)
+ var remaining_bytes = peer.get_data(peer.get_available_bytes())
+
+ return from_bytes(remaining_bytes[1])
diff --git a/packets/character_server_information.gd b/packets/character_server_information.gd
new file mode 100644
index 0000000..f67b065
--- /dev/null
+++ b/packets/character_server_information.gd
@@ -0,0 +1,70 @@
+class_name CharacterServerInformation
+extends PacketChunk
+
+
+## Byte Type: u32
+## Byte Length: 4
+var server_ip: PackedByteArray
+
+## Byte Type: u16
+## Byte Length: 2
+var server_port: int
+
+## Byte Type: u8
+## Byte Length: 20
+var server_name: String
+
+## Byte Type: u16
+## Byte Length: 2
+var user_count: int
+
+## Byte Type: u16
+## Byte Length: 2
+var server_type: int
+
+## Byte Type: u16
+## Byte Length: 2
+var display_new: int
+
+## Byte Type: u8
+## Byte Length: 128
+var unknown: PackedByteArray
+
+
+func _init() -> void:
+ byte_length = 160
+
+
+func get_server_ip():
+ return "%s.%s.%s.%s" % [
+ server_ip.decode_u8(0),
+ server_ip.decode_u8(1),
+ server_ip.decode_u8(2),
+ server_ip.decode_u8(3)
+ ]
+
+
+static func from_bytes(bytes: PackedByteArray):
+ var info = CharacterServerInformation.new()
+
+ info.server_ip = bytes.slice(0, 4)
+ info.server_port = bytes.decode_u16(4)
+ info.server_name = bytes.slice(6, 6 + 20).get_string_from_utf8()
+ info.user_count = bytes.decode_u16(26)
+ info.server_type = bytes.decode_u16(28)
+ info.display_new = bytes.decode_u16(30)
+ info.unknown = bytes.slice(32)
+
+ return info
+
+
+static func array_from_bytes(bytes: PackedByteArray) -> Array:
+ var array = []
+
+ var offset = 0
+ while offset < bytes.size():
+ var chunk = from_bytes(bytes.slice(offset))
+ array.append(chunk)
+ offset += chunk.byte_length
+
+ return array
diff --git a/packets/character_server_login_packet.gd b/packets/character_server_login_packet.gd
index e6ba07b..0e3116f 100644
--- a/packets/character_server_login_packet.gd
+++ b/packets/character_server_login_packet.gd
@@ -2,25 +2,31 @@ class_name CharacterServerLoginPacket
extends Packet
+static var header := 0x0065
+
+
+## Byte Type: u32
## Byte Length: 4
var account_id: int
+## Byte Type: u32
## Byte Length: 4
var login_id1: int
+## Byte Type: u32
## Byte Length: 4
var login_id2: int
+## Byte Type: u16
## Byte Length: 2
var unknown: int
+## Byte Type: u8
## Byte Length: 1
var gender: Constants.Gender
func to_bytes():
- var header = PackedByteArray([101, 0])
-
var payload = PackedByteArray([])
payload.resize(15)
payload.encode_u32(0, account_id)
@@ -29,4 +35,4 @@ func to_bytes():
payload.encode_u16(12, unknown)
payload.encode_u8(14, gender)
- return header + payload
+ return get_header() + payload
diff --git a/packets/login_server_login_packet.gd b/packets/login_server_login_packet.gd
index 29f23cd..5b4c1f3 100644
--- a/packets/login_server_login_packet.gd
+++ b/packets/login_server_login_packet.gd
@@ -2,6 +2,10 @@ class_name LoginServerLoginPacket
extends Packet
+static var header := 0x064
+
+
+## Byte Type: u32
## Byte Length: 4
var version: int = 0
@@ -11,13 +15,12 @@ var username: String
## Byte Length: 24
var password: String
+## Byte Type: u8
## Byte Length: 1
var client_type: int = 0
func to_bytes():
- var header = PackedByteArray([100, 0])
-
var username_bytes = username.to_utf8_buffer()
username_bytes.resize(24)
@@ -27,8 +30,11 @@ func to_bytes():
var payload = PackedByteArray([])
payload.resize(4)
payload.encode_u32(0, version)
+
payload.append_array(username_bytes)
payload.append_array(password_bytes)
- payload.append(client_type)
- return header + payload
+ payload.resize(53)
+ payload.encode_u8(52, client_type)
+
+ return get_header() + payload
diff --git a/packets/login_server_login_success_packet.gd b/packets/login_server_login_success_packet.gd
index 3d74289..fd7dbf1 100644
--- a/packets/login_server_login_success_packet.gd
+++ b/packets/login_server_login_success_packet.gd
@@ -2,30 +2,36 @@ class_name LoginServerLoginSuccessPacket
extends Packet
+static var header := 0x0ac4
+
+
+## Byte Type: u32
## Byte Length: 4
var login_id1: int
+## Byte Type: u32
## Byte Length: 4
var account_id: int
+## Byte Type: u32
## Byte Length: 4
var login_id2: int
## Deprecated and always 0 on rAthena
+## Byte Type: u32
## Byte Length: 4
var ip_address: PackedByteArray
## Deprecated and always 0 on rAthena
-## Byte Length: 24
-var name: String
-
-## Always 0 on rAthena
-## Byte Length: 2
-var unknown: int
+## Byte Type: u8
+## Byte Length: 26
+var last_login: PackedByteArray
+## Byte Type: u8
## Byte Length: 1
var gender: Constants.Gender
+## Byte Type: u8
## Byte Length: 17
var auth_token: String
@@ -39,16 +45,15 @@ static func from_bytes(bytes: PackedByteArray):
packet.account_id = bytes.decode_u32(4)
packet.login_id2 = bytes.decode_u32(8)
packet.ip_address = bytes.slice(12, 16)
- packet.name = bytes.slice(16, 16 + 24).get_string_from_utf8()
- packet.unknown = bytes.decode_u16(40)
+ packet.last_login = bytes.slice(16, 16 + 26)
packet.gender = bytes[42]
- packet.auth_token = bytes.slice(43, 43 + 17 - 1).get_string_from_utf8()
+ packet.auth_token = bytes.slice(43, 43 + 17).get_string_from_utf8()
packet.character_server_information = CharacterServerInformation.array_from_bytes(bytes.slice(60))
return packet
static func from_bytes_via_peer(peer: StreamPeer):
- var _header = peer.get_data(4)
+ var _header = peer.get_data(4) # 2 = header, 2 = packet_size
var remaining_bytes = peer.get_data(peer.get_available_bytes())
return from_bytes(remaining_bytes[1])
diff --git a/packets/map_server_login_packet.gd b/packets/map_server_login_packet.gd
index 62af086..89d0108 100644
--- a/packets/map_server_login_packet.gd
+++ b/packets/map_server_login_packet.gd
@@ -2,28 +2,35 @@ class_name MapServerLoginPacket
extends Packet
+static var header := 0x0436
+
+
+## Byte Type: u32
## Byte Length: 4
var account_id: int
+## Byte Type: u32
## Byte Length: 4
var character_id: int
+## Byte Type: u32
## Byte Length: 4
var login_id1: int
+## Byte Type: u32
## Byte Length: 4
var client_tick: int = 100
+## Byte Type: u8
## Byte Length: 1
var gender: Constants.Gender
+## Byte Type: u32
## Byte Length: 4
var unknown: int = 0
func to_bytes():
- var header = PackedByteArray([54, 4])
-
var payload = PackedByteArray([])
payload.resize(21)
payload.encode_u32(0, account_id)
@@ -33,4 +40,4 @@ func to_bytes():
payload.encode_u8(16, gender)
payload.encode_u32(17, unknown)
- return header + payload
+ return get_header() + payload
diff --git a/packets/map_server_login_success_packet.gd b/packets/map_server_login_success_packet.gd
new file mode 100644
index 0000000..9eecc65
--- /dev/null
+++ b/packets/map_server_login_success_packet.gd
@@ -0,0 +1,48 @@
+class_name MapServerLoginSuccessPacket
+extends Packet
+
+
+static var header := 0x02eb
+
+
+## Byte Type: u32
+## Byte Length: 4
+var client_tick: int
+
+## Byte Type: u8
+## Byte Length: 3
+var position: PackedByteArray
+
+## Byte Type: u8
+## Byte Length: 2
+## Always [5, 5] on rAthena
+var ignored: PackedByteArray
+
+## Byte Type: u16
+## Byte Length: 2
+var font: int
+
+
+func get_position():
+ return Vector2(
+ position[1] >> 6 | position[0] << 2,
+ position[2] >> 4 | (position[1] & 0b111111) << 4
+ )
+
+
+static func from_bytes(bytes: PackedByteArray):
+ var packet = MapServerLoginSuccessPacket.new()
+
+ packet.client_tick = bytes.decode_u32(0)
+ packet.position = bytes.slice(4, 4 + 3)
+ packet.ignored = bytes.slice(7, 7 + 2)
+ packet.font = bytes.decode_u32(9)
+
+ return packet
+
+
+static func from_bytes_via_peer(peer: StreamPeer):
+ var _header = peer.get_data(2)
+ var remaining_bytes = peer.get_data(peer.get_available_bytes())
+
+ return from_bytes(remaining_bytes[1])
diff --git a/packets/packet.gd b/packets/packet.gd
index ea1621c..9f82782 100644
--- a/packets/packet.gd
+++ b/packets/packet.gd
@@ -1 +1,24 @@
class_name Packet
+
+
+#static var header: int = 0
+
+var byte_length: int = 0
+
+
+## Override if packet has variable length
+func get_byte_length() -> int:
+ return byte_length
+
+
+## Get header to prepend to the packet. [br]
+## [param packet_length] is only needed when the packet has a variable length.
+func get_header(packet_length: int = 0) -> PackedByteArray:
+ var bytes = PackedByteArray([0,0])
+ bytes.encode_u16(0, self.header)
+
+ if packet_length > 0:
+ bytes.resize(4)
+ bytes.encode_u16(2, packet_length)
+
+ return bytes
diff --git a/packets/packet_chunk.gd b/packets/packet_chunk.gd
new file mode 100644
index 0000000..2bd8bc6
--- /dev/null
+++ b/packets/packet_chunk.gd
@@ -0,0 +1,10 @@
+class_name PacketChunk
+
+
+var byte_length: int:
+ get = get_byte_length
+
+
+## to be overriden
+func get_byte_length() -> int:
+ return byte_length
diff --git a/packets/request_character_list_packet.gd b/packets/request_character_list_packet.gd
index eca61ad..e347abd 100644
--- a/packets/request_character_list_packet.gd
+++ b/packets/request_character_list_packet.gd
@@ -2,7 +2,8 @@ class_name RequestCharacterListPacket
extends Packet
+static var header := 0x09a1
+
+
func to_bytes():
- var header = PackedByteArray([161, 9])
-
- return header
+ return get_header()
diff --git a/packets/request_character_list_success_packet.gd b/packets/request_character_list_success_packet.gd
index 0b6cea8..431e8ca 100644
--- a/packets/request_character_list_success_packet.gd
+++ b/packets/request_character_list_success_packet.gd
@@ -12,8 +12,9 @@ static func from_bytes(bytes: PackedByteArray):
return packet
+
static func from_bytes_via_peer(peer: StreamPeer):
- var _header = peer.get_data(4)
+ var _header = peer.get_data(4) # 2 = header, 2 = length
var remaining_bytes = peer.get_data(peer.get_available_bytes())
return from_bytes(remaining_bytes[1])
diff --git a/packets/select_character_packet.gd b/packets/select_character_packet.gd
new file mode 100644
index 0000000..18843cc
--- /dev/null
+++ b/packets/select_character_packet.gd
@@ -0,0 +1,18 @@
+class_name SelectCharacterPacket
+extends Packet
+
+
+static var header := 0x0066
+
+
+## Byte Type: u8
+## Byte Length: 1
+var selected_slot: int
+
+
+func to_bytes():
+ var payload = PackedByteArray([])
+ payload.resize(1)
+ payload.encode_u8(0, selected_slot)
+
+ return get_header() + payload