From cda1fdcefdb740e8f75bef435166392e1b1d3ca0 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 30 Mar 2025 09:50:21 -0400 Subject: [PATCH 01/14] feat: rsbuf packets implementation --- src/category.rs | 23 + src/lib.rs | 564 ++++++++++++- src/message.rs | 2120 +++++++++++++++++++++++++++++++++++++++++++++-- src/player.rs | 21 + src/priority.rs | 12 + src/prot.rs | 287 ++++++- src/renderer.rs | 17 +- 7 files changed, 2945 insertions(+), 99 deletions(-) create mode 100644 src/category.rs create mode 100644 src/priority.rs diff --git a/src/category.rs b/src/category.rs new file mode 100644 index 0000000..8ac0cdb --- /dev/null +++ b/src/category.rs @@ -0,0 +1,23 @@ +#![allow(non_camel_case_types)] + +use wasm_bindgen::prelude::wasm_bindgen; + +#[repr(u8)] +#[wasm_bindgen] +// todo: measure how many events we should expect to receive from the client +// osrs has this as 50/10 but we know that's not true in rs2 +// todo: determine which packets belong in which category for this era +pub enum ClientProtCategory { + CLIENT_EVENT = 0, + USER_EVENT = 1, + RESTRICTED_EVENT = 2, // flood restricted events +} + +#[repr(u8)] +#[wasm_bindgen] +// packet decoding limit per tick, exceeding this ends decoding and picks up where it left off on the next tick +pub enum ClientProtCategoryLimit { + CLIENT_EVENT = 20, + USER_EVENT = 5, + RESTRICTED_EVENT = 2, +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 811e758..2a6519c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,11 @@ use crate::coord::CoordGrid; use crate::grid::ZoneMap; use crate::info::{NpcInfo, PlayerInfo}; +use crate::message::{AnticheatCycle1, AnticheatCycle2, AnticheatCycle3, AnticheatCycle4, AnticheatCycle5, AnticheatCycle6, AnticheatOp1, AnticheatOp2, AnticheatOp3, AnticheatOp4, AnticheatOp5, AnticheatOp6, AnticheatOp7, AnticheatOp8, AnticheatOp9, ChatSetMode, ClientCheat, CloseModal, EventCameraPosition, EventTracking, FriendListAdd, FriendListDel, IdleTimer, IfButton, IfOpenMain, IfOpenSide, IfPlayerDesign, IgnoreListAdd, IgnoreListDel, IncomingPacket, InfoMessage, InvButton, InvButtonD, MessageDecoder, MessageEncoder, MessageGame, MessagePrivate, MessagePublic, MoveClick, NoTimeout, OpHeld, OpHeldT, OpHeldU, OpLoc, OpLocT, OpLocU, OpNpc, OpNpcT, OpNpcU, OpObj, OpObjT, OpObjU, OpPlayer, OpPlayerT, OpPlayerU, OutgoingPacket, RebuildGetMaps, ReportAbuse, ResumePCountDialog, ResumePauseButton, TutorialClickSide}; use crate::npc::Npc; +use crate::packet::Packet; use crate::player::{Chat, ExactMove, Player}; +use crate::prot::{ClientInternalProt, ClientProt}; use crate::renderer::{NpcRenderer, PlayerRenderer}; use crate::visibility::Visibility; use once_cell::sync::Lazy; @@ -24,6 +27,8 @@ mod info; mod grid; mod npc; mod visibility; +mod priority; +mod category; static mut PLAYERS: Lazy>> = Lazy::new(|| vec![None; 2048]); static mut PLAYER_GRID: Lazy>> = Lazy::new(|| HashMap::with_capacity(2048)); @@ -153,13 +158,13 @@ pub unsafe fn compute_player( } #[wasm_bindgen(js_name = playerInfo)] -pub unsafe fn player_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Vec { +pub unsafe fn player_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option> { if pid == -1 { - return vec![]; + return None; } if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return PLAYER_INFO.encode( + return Some(PLAYER_INFO.encode( pos, &mut **addr_of_mut!(PLAYER_RENDERER), &**addr_of!(PLAYERS), @@ -169,10 +174,10 @@ pub unsafe fn player_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) dx, dz, rebuild, - ); + )); } - return vec![]; + return None; } #[wasm_bindgen(js_name = addPlayer)] @@ -281,13 +286,13 @@ pub unsafe fn compute_npc( } #[wasm_bindgen(js_name = npcInfo)] -pub unsafe fn npc_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Vec { +pub unsafe fn npc_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option> { if pid == -1 { - return vec![]; + return None; } if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return NPC_INFO.encode( + return Some(NPC_INFO.encode( pos, &mut **addr_of_mut!(NPC_RENDERER), &mut **addr_of_mut!(NPCS), @@ -296,10 +301,10 @@ pub unsafe fn npc_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> dx, dz, rebuild - ); + )); } - return vec![]; + return None; } #[wasm_bindgen(js_name = addNpc)] @@ -371,3 +376,542 @@ pub unsafe fn cleanup_player_buildarea(pid: i32) { player.build.cleanup(); } } + +// ---- encoders + +#[wasm_bindgen(js_name = ifOpenMain)] +pub unsafe fn if_open_main(pid: i32, component: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfOpenMain::new(component)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifOpenSide)] +pub unsafe fn if_open_side(pid: i32, component: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfOpenSide::new(component)); + } + + return None; +} + +#[wasm_bindgen(js_name = messageGame)] +pub unsafe fn message_game(pid: i32, msg: String) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&MessageGame::new(msg)); + } + + return None; +} + +#[wasm_bindgen(js_name = nextBufferedWrite)] +pub unsafe fn next_buffered_write(pid: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write_queue.pop_front(); + } + + return None; +} + +// ---- decoders + +#[wasm_bindgen(js_name = nextBufferedRead)] +pub unsafe fn next_buffered_read(id: i32) -> Option { + return match id { + n if n == ClientInternalProt::CLIENT_CHEAT as i32 => Some(IncomingPacket::new(ClientProt::CLIENT_CHEAT as i32, ClientCheat::length())), + n if n == ClientInternalProt::CLOSE_MODAL as i32 => Some(IncomingPacket::new(ClientProt::CLOSE_MODAL as i32, CloseModal::length())), + n if n == ClientInternalProt::FRIENDLIST_ADD as i32 => Some(IncomingPacket::new(ClientProt::FRIENDLIST_ADD as i32, FriendListAdd::length())), + n if n == ClientInternalProt::FRIENDLIST_DEL as i32 => Some(IncomingPacket::new(ClientProt::FRIENDLIST_DEL as i32, FriendListDel::length())), + n if n == ClientInternalProt::IDLE_TIMER as i32 => Some(IncomingPacket::new(ClientProt::IDLE_TIMER as i32, IdleTimer::length())), + n if n == ClientInternalProt::IF_BUTTON as i32 => Some(IncomingPacket::new(ClientProt::IF_BUTTON as i32, IfButton::length())), + n if n == ClientInternalProt::IF_PLAYERDESIGN as i32 => Some(IncomingPacket::new(ClientProt::IF_PLAYERDESIGN as i32, IfPlayerDesign::length())), + n if n == ClientInternalProt::IGNORELIST_ADD as i32 => Some(IncomingPacket::new(ClientProt::IGNORELIST_ADD as i32, IgnoreListAdd::length())), + n if n == ClientInternalProt::IGNORELIST_DEL as i32 => Some(IncomingPacket::new(ClientProt::IGNORELIST_DEL as i32, IgnoreListDel::length())), + n if n == ClientInternalProt::INV_BUTTON1 as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTON1 as i32, InvButton::length())), + n if n == ClientInternalProt::INV_BUTTON2 as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTON2 as i32, InvButton::length())), + n if n == ClientInternalProt::INV_BUTTON3 as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTON3 as i32, InvButton::length())), + n if n == ClientInternalProt::INV_BUTTON4 as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTON4 as i32, InvButton::length())), + n if n == ClientInternalProt::INV_BUTTON5 as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTON5 as i32, InvButton::length())), + n if n == ClientInternalProt::INV_BUTTOND as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTOND as i32, InvButtonD::length())), + n if n == ClientInternalProt::MESSAGE_PRIVATE as i32 => Some(IncomingPacket::new(ClientProt::MESSAGE_PRIVATE as i32, MessagePrivate::length())), + n if n == ClientInternalProt::MESSAGE_PUBLIC as i32 => Some(IncomingPacket::new(ClientProt::MESSAGE_PUBLIC as i32, MessagePublic::length())), + n if n == ClientInternalProt::MOVE_MINIMAPCLICK as i32 => Some(IncomingPacket::new(ClientProt::MOVE_MINIMAPCLICK as i32, MoveClick::length())), + n if n == ClientInternalProt::MOVE_GAMECLICK as i32 => Some(IncomingPacket::new(ClientProt::MOVE_GAMECLICK as i32, MoveClick::length())), + n if n == ClientInternalProt::MOVE_OPCLICK as i32 => Some(IncomingPacket::new(ClientProt::MOVE_OPCLICK as i32, MoveClick::length())), + n if n == ClientInternalProt::NO_TIMEOUT as i32 => Some(IncomingPacket::new(ClientProt::NO_TIMEOUT as i32, NoTimeout::length())), + n if n == ClientInternalProt::OPHELD1 as i32 => Some(IncomingPacket::new(ClientProt::OPHELD1 as i32, OpHeld::length())), + n if n == ClientInternalProt::OPHELD2 as i32 => Some(IncomingPacket::new(ClientProt::OPHELD2 as i32, OpHeld::length())), + n if n == ClientInternalProt::OPHELD3 as i32 => Some(IncomingPacket::new(ClientProt::OPHELD3 as i32, OpHeld::length())), + n if n == ClientInternalProt::OPHELD4 as i32 => Some(IncomingPacket::new(ClientProt::OPHELD4 as i32, OpHeld::length())), + n if n == ClientInternalProt::OPHELD5 as i32 => Some(IncomingPacket::new(ClientProt::OPHELD5 as i32, OpHeld::length())), + n if n == ClientInternalProt::OPHELDT as i32 => Some(IncomingPacket::new(ClientProt::OPHELDT as i32, OpHeldT::length())), + n if n == ClientInternalProt::OPHELDU as i32 => Some(IncomingPacket::new(ClientProt::OPHELDU as i32, OpHeldU::length())), + n if n == ClientInternalProt::OPLOC1 as i32 => Some(IncomingPacket::new(ClientProt::OPLOC1 as i32, OpLoc::length())), + n if n == ClientInternalProt::OPLOC2 as i32 => Some(IncomingPacket::new(ClientProt::OPLOC2 as i32, OpLoc::length())), + n if n == ClientInternalProt::OPLOC3 as i32 => Some(IncomingPacket::new(ClientProt::OPLOC3 as i32, OpLoc::length())), + n if n == ClientInternalProt::OPLOC4 as i32 => Some(IncomingPacket::new(ClientProt::OPLOC4 as i32, OpLoc::length())), + n if n == ClientInternalProt::OPLOC5 as i32 => Some(IncomingPacket::new(ClientProt::OPLOC5 as i32, OpLoc::length())), + n if n == ClientInternalProt::OPLOCT as i32 => Some(IncomingPacket::new(ClientProt::OPLOCT as i32, OpLocT::length())), + n if n == ClientInternalProt::OPLOCU as i32 => Some(IncomingPacket::new(ClientProt::OPLOCU as i32, OpLocU::length())), + n if n == ClientInternalProt::OPNPC1 as i32 => Some(IncomingPacket::new(ClientProt::OPNPC1 as i32, OpNpc::length())), + n if n == ClientInternalProt::OPNPC2 as i32 => Some(IncomingPacket::new(ClientProt::OPNPC2 as i32, OpNpc::length())), + n if n == ClientInternalProt::OPNPC3 as i32 => Some(IncomingPacket::new(ClientProt::OPNPC3 as i32, OpNpc::length())), + n if n == ClientInternalProt::OPNPC4 as i32 => Some(IncomingPacket::new(ClientProt::OPNPC4 as i32, OpNpc::length())), + n if n == ClientInternalProt::OPNPC5 as i32 => Some(IncomingPacket::new(ClientProt::OPNPC5 as i32, OpNpc::length())), + n if n == ClientInternalProt::OPNPCT as i32 => Some(IncomingPacket::new(ClientProt::OPNPCT as i32, OpNpcT::length())), + n if n == ClientInternalProt::OPNPCU as i32 => Some(IncomingPacket::new(ClientProt::OPNPCU as i32, OpNpcU::length())), + n if n == ClientInternalProt::OPOBJ1 as i32 => Some(IncomingPacket::new(ClientProt::OPOBJ1 as i32, OpObj::length())), + n if n == ClientInternalProt::OPOBJ2 as i32 => Some(IncomingPacket::new(ClientProt::OPOBJ2 as i32, OpObj::length())), + n if n == ClientInternalProt::OPOBJ3 as i32 => Some(IncomingPacket::new(ClientProt::OPOBJ3 as i32, OpObj::length())), + n if n == ClientInternalProt::OPOBJ4 as i32 => Some(IncomingPacket::new(ClientProt::OPOBJ4 as i32, OpObj::length())), + n if n == ClientInternalProt::OPOBJ5 as i32 => Some(IncomingPacket::new(ClientProt::OPOBJ5 as i32, OpObj::length())), + n if n == ClientInternalProt::OPOBJT as i32 => Some(IncomingPacket::new(ClientProt::OPOBJT as i32, OpObjT::length())), + n if n == ClientInternalProt::OPOBJU as i32 => Some(IncomingPacket::new(ClientProt::OPOBJU as i32, OpObjU::length())), + n if n == ClientInternalProt::OPPLAYER1 as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYER1 as i32, OpPlayer::length())), + n if n == ClientInternalProt::OPPLAYER2 as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYER2 as i32, OpPlayer::length())), + n if n == ClientInternalProt::OPPLAYER3 as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYER3 as i32, OpPlayer::length())), + n if n == ClientInternalProt::OPPLAYER4 as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYER4 as i32, OpPlayer::length())), + n if n == ClientInternalProt::OPPLAYERT as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYERT as i32, OpPlayerT::length())), + n if n == ClientInternalProt::OPPLAYERU as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYERU as i32, OpPlayerU::length())), + n if n == ClientInternalProt::REBUILD_GETMAPS as i32 => Some(IncomingPacket::new(ClientProt::REBUILD_GETMAPS as i32, RebuildGetMaps::length())), + n if n == ClientInternalProt::RESUME_PAUSEBUTTON as i32 => Some(IncomingPacket::new(ClientProt::RESUME_PAUSEBUTTON as i32, ResumePauseButton::length())), + n if n == ClientInternalProt::RESUME_P_COUNTDIALOG as i32 => Some(IncomingPacket::new(ClientProt::RESUME_P_COUNTDIALOG as i32, ResumePCountDialog::length())), + n if n == ClientInternalProt::TUTORIAL_CLICKSIDE as i32 => Some(IncomingPacket::new(ClientProt::TUTORIAL_CLICKSIDE as i32, TutorialClickSide::length())), + n if n == ClientInternalProt::CHAT_SETMODE as i32 => Some(IncomingPacket::new(ClientProt::CHAT_SETMODE as i32, ChatSetMode::length())), + n if n == ClientInternalProt::EVENT_TRACKING as i32 => Some(IncomingPacket::new(ClientProt::EVENT_TRACKING as i32, EventTracking::length())), + n if n == ClientInternalProt::REPORT_ABUSE as i32 => Some(IncomingPacket::new(ClientProt::REPORT_ABUSE as i32, ReportAbuse::length())), + n if n == ClientInternalProt::EVENT_CAMERA_POSITION as i32 => Some(IncomingPacket::new(ClientProt::EVENT_CAMERA_POSITION as i32, EventCameraPosition::length())), + n if n == ClientInternalProt::ANTICHEAT_OPLOGIC1 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC1 as i32, AnticheatOp1::length())), + n if n == ClientInternalProt::ANTICHEAT_OPLOGIC2 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC2 as i32, AnticheatOp2::length())), + n if n == ClientInternalProt::ANTICHEAT_OPLOGIC3 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC3 as i32, AnticheatOp3::length())), + n if n == ClientInternalProt::ANTICHEAT_OPLOGIC4 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC4 as i32, AnticheatOp4::length())), + n if n == ClientInternalProt::ANTICHEAT_OPLOGIC5 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC5 as i32, AnticheatOp5::length())), + n if n == ClientInternalProt::ANTICHEAT_OPLOGIC6 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC6 as i32, AnticheatOp6::length())), + n if n == ClientInternalProt::ANTICHEAT_OPLOGIC7 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC7 as i32, AnticheatOp7::length())), + n if n == ClientInternalProt::ANTICHEAT_OPLOGIC8 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC8 as i32, AnticheatOp8::length())), + n if n == ClientInternalProt::ANTICHEAT_OPLOGIC9 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC9 as i32, AnticheatOp9::length())), + n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC1 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC1 as i32, AnticheatCycle1::length())), + n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC2 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC2 as i32, AnticheatCycle2::length())), + n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC3 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC3 as i32, AnticheatCycle3::length())), + n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC4 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC4 as i32, AnticheatCycle4::length())), + n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC5 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC5 as i32, AnticheatCycle5::length())), + n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC6 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC6 as i32, AnticheatCycle6::length())), + + _ => None, + }; +} + +unsafe fn read(bytes: Vec) -> Packet { + let mut buf: Packet = Packet::new(bytes.len()); + buf.pdata(&bytes, 0, bytes.len()); + buf.pos = 0; + return buf; +} + +#[wasm_bindgen(js_name = clientCheat)] +pub unsafe fn clientCheat(bytes: Vec) -> Option { + return Some(ClientCheat::decode(ClientProt::CLIENT_CHEAT, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = closeModal)] +pub unsafe fn close_modal(bytes: Vec) -> Option { + return Some(CloseModal::decode(ClientProt::CLOSE_MODAL, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = friendListAdd)] +pub unsafe fn friend_list_add(bytes: Vec) -> Option { + return Some(FriendListAdd::decode(ClientProt::FRIENDLIST_ADD, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = friendListDel)] +pub unsafe fn friend_list_del(bytes: Vec) -> Option { + return Some(FriendListDel::decode(ClientProt::FRIENDLIST_DEL, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = idleTimer)] +pub unsafe fn idle_timer(bytes: Vec) -> Option { + return Some(IdleTimer::decode(ClientProt::IDLE_TIMER, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = ifButton)] +pub unsafe fn if_button(bytes: Vec) -> Option { + return Some(IfButton::decode(ClientProt::IF_BUTTON, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = ifPlayerDesign)] +pub unsafe fn if_player_design(bytes: Vec) -> Option { + return Some(IfPlayerDesign::decode(ClientProt::IF_PLAYERDESIGN, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = ignoreListAdd)] +pub unsafe fn ignore_list_add(bytes: Vec) -> Option { + return Some(IgnoreListAdd::decode(ClientProt::IGNORELIST_ADD, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = ignoreListDel)] +pub unsafe fn ignore_list_del(bytes: Vec) -> Option { + return Some(IgnoreListDel::decode(ClientProt::IGNORELIST_DEL, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = invButton1)] +pub unsafe fn inv_button1(bytes: Vec) -> Option { + return Some(InvButton::decode(ClientProt::INV_BUTTON1, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = invButton2)] +pub unsafe fn inv_button2(bytes: Vec) -> Option { + return Some(InvButton::decode(ClientProt::INV_BUTTON2, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = invButton3)] +pub unsafe fn inv_button3(bytes: Vec) -> Option { + return Some(InvButton::decode(ClientProt::INV_BUTTON3, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = invButton4)] +pub unsafe fn inv_button4(bytes: Vec) -> Option { + return Some(InvButton::decode(ClientProt::INV_BUTTON4, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = invButton5)] +pub unsafe fn inv_button5(bytes: Vec) -> Option { + return Some(InvButton::decode(ClientProt::INV_BUTTON5, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = invButtonD)] +pub unsafe fn inv_buttonD(bytes: Vec) -> Option { + return Some(InvButtonD::decode(ClientProt::INV_BUTTOND, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = messagePrivate)] +pub unsafe fn message_private(bytes: Vec) -> Option { + return Some(MessagePrivate::decode(ClientProt::MESSAGE_PRIVATE, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = messagePublic)] +pub unsafe fn message_public(bytes: Vec) -> Option { + return Some(MessagePublic::decode(ClientProt::MESSAGE_PUBLIC, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = moveMinimapClick)] +pub unsafe fn move_minimap_click(bytes: Vec) -> Option { + return Some(MoveClick::decode(ClientProt::MOVE_MINIMAPCLICK, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = moveGameClick)] +pub unsafe fn move_game_click(bytes: Vec) -> Option { + return Some(MoveClick::decode(ClientProt::MOVE_GAMECLICK, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = moveOpClick)] +pub unsafe fn move_op_click(bytes: Vec) -> Option { + return Some(MoveClick::decode(ClientProt::MOVE_OPCLICK, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = noTimeout)] +pub unsafe fn no_timeout(bytes: Vec) -> Option { + return Some(NoTimeout::decode(ClientProt::NO_TIMEOUT, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opheld1)] +pub unsafe fn opheld1(bytes: Vec) -> Option { + return Some(OpHeld::decode(ClientProt::OPHELD1, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opheld2)] +pub unsafe fn opheld2(bytes: Vec) -> Option { + return Some(OpHeld::decode(ClientProt::OPHELD2, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opheld3)] +pub unsafe fn opheld3(bytes: Vec) -> Option { + return Some(OpHeld::decode(ClientProt::OPHELD3, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opheld4)] +pub unsafe fn opheld4(bytes: Vec) -> Option { + return Some(OpHeld::decode(ClientProt::OPHELD4, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opheld5)] +pub unsafe fn opheld5(bytes: Vec) -> Option { + return Some(OpHeld::decode(ClientProt::OPHELD5, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opheldT)] +pub unsafe fn opheldT(bytes: Vec) -> Option { + return Some(OpHeldT::decode(ClientProt::OPHELDT, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opheldU)] +pub unsafe fn opheldU(bytes: Vec) -> Option { + return Some(OpHeldU::decode(ClientProt::OPHELDU, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = oploc1)] +pub unsafe fn oploc1(bytes: Vec) -> Option { + return Some(OpLoc::decode(ClientProt::OPLOC1, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = oploc2)] +pub unsafe fn oploc2(bytes: Vec) -> Option { + return Some(OpLoc::decode(ClientProt::OPLOC2, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = oploc3)] +pub unsafe fn oploc3(bytes: Vec) -> Option { + return Some(OpLoc::decode(ClientProt::OPLOC3, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = oploc4)] +pub unsafe fn oploc4(bytes: Vec) -> Option { + return Some(OpLoc::decode(ClientProt::OPLOC4, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = oploc5)] +pub unsafe fn oploc5(bytes: Vec) -> Option { + return Some(OpLoc::decode(ClientProt::OPLOC5, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = oplocT)] +pub unsafe fn oplocT(bytes: Vec) -> Option { + return Some(OpLocT::decode(ClientProt::OPLOCT, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = oplocU)] +pub unsafe fn oplocU(bytes: Vec) -> Option { + return Some(OpLocU::decode(ClientProt::OPLOCU, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opnpc1)] +pub unsafe fn opnpc1(bytes: Vec) -> Option { + return Some(OpNpc::decode(ClientProt::OPNPC1, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opnpc2)] +pub unsafe fn opnpc2(bytes: Vec) -> Option { + return Some(OpNpc::decode(ClientProt::OPNPC2, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opnpc3)] +pub unsafe fn opnpc3(bytes: Vec) -> Option { + return Some(OpNpc::decode(ClientProt::OPNPC3, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opnpc4)] +pub unsafe fn opnpc4(bytes: Vec) -> Option { + return Some(OpNpc::decode(ClientProt::OPNPC4, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opnpc5)] +pub unsafe fn opnpc5(bytes: Vec) -> Option { + return Some(OpNpc::decode(ClientProt::OPNPC5, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opnpcT)] +pub unsafe fn opnpcT(bytes: Vec) -> Option { + return Some(OpNpcT::decode(ClientProt::OPNPCT, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opnpcU)] +pub unsafe fn opnpcU(bytes: Vec) -> Option { + return Some(OpNpcU::decode(ClientProt::OPNPCU, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opobj1)] +pub unsafe fn opobj1(bytes: Vec) -> Option { + return Some(OpObj::decode(ClientProt::OPOBJ1, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opobj2)] +pub unsafe fn opobj2(bytes: Vec) -> Option { + return Some(OpObj::decode(ClientProt::OPOBJ2, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opobj3)] +pub unsafe fn opobj3(bytes: Vec) -> Option { + return Some(OpObj::decode(ClientProt::OPOBJ3, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opobj4)] +pub unsafe fn opobj4(bytes: Vec) -> Option { + return Some(OpObj::decode(ClientProt::OPOBJ4, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opobj5)] +pub unsafe fn opobj5(bytes: Vec) -> Option { + return Some(OpObj::decode(ClientProt::OPOBJ5, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opobjT)] +pub unsafe fn opobjT(bytes: Vec) -> Option { + return Some(OpObjT::decode(ClientProt::OPOBJT, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opobjU)] +pub unsafe fn opobjU(bytes: Vec) -> Option { + return Some(OpObjU::decode(ClientProt::OPOBJU, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opplayer1)] +pub unsafe fn opplayer1(bytes: Vec) -> Option { + return Some(OpPlayer::decode(ClientProt::OPPLAYER1, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opplayer2)] +pub unsafe fn opplayer2(bytes: Vec) -> Option { + return Some(OpPlayer::decode(ClientProt::OPPLAYER2, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opplayer3)] +pub unsafe fn opplayer3(bytes: Vec) -> Option { + return Some(OpPlayer::decode(ClientProt::OPPLAYER3, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opplayer4)] +pub unsafe fn opplayer4(bytes: Vec) -> Option { + return Some(OpPlayer::decode(ClientProt::OPPLAYER4, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opplayerT)] +pub unsafe fn opplayerT(bytes: Vec) -> Option { + return Some(OpPlayerT::decode(ClientProt::OPPLAYERT, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = opplayerU)] +pub unsafe fn opplayerU(bytes: Vec) -> Option { + return Some(OpPlayerU::decode(ClientProt::OPPLAYERU, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = rebuildGetMaps)] +pub unsafe fn rebuild_getmaps(bytes: Vec) -> Option { + return Some(RebuildGetMaps::decode(ClientProt::REBUILD_GETMAPS, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = resumePauseButton)] +pub unsafe fn resume_pausebutton(bytes: Vec) -> Option { + return Some(ResumePauseButton::decode(ClientProt::RESUME_PAUSEBUTTON, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = resumeCountDialog)] +pub unsafe fn resume_countdialog(bytes: Vec) -> Option { + return Some(ResumePCountDialog::decode(ClientProt::RESUME_P_COUNTDIALOG, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = tutorialClickSide)] +pub unsafe fn tutorial_clickside(bytes: Vec) -> Option { + return Some(TutorialClickSide::decode(ClientProt::TUTORIAL_CLICKSIDE, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = chatSetMode)] +pub unsafe fn chat_setmode(bytes: Vec) -> Option { + return Some(ChatSetMode::decode(ClientProt::CHAT_SETMODE, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = eventTracking)] +pub unsafe fn event_tracking(bytes: Vec) -> Option { + return Some(EventTracking::decode(ClientProt::EVENT_TRACKING, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = reportAbuse)] +pub unsafe fn report_abuse(bytes: Vec) -> Option { + return Some(ReportAbuse::decode(ClientProt::REPORT_ABUSE, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = eventCameraPosition)] +pub unsafe fn event_camera_position(bytes: Vec) -> Option { + return Some(EventCameraPosition::decode(ClientProt::EVENT_CAMERA_POSITION, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatOp1)] +pub unsafe fn anticheatop1(bytes: Vec) -> Option { + return Some(AnticheatOp1::decode(ClientProt::ANTICHEAT_OPLOGIC1, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatOp2)] +pub unsafe fn anticheatop2(bytes: Vec) -> Option { + return Some(AnticheatOp2::decode(ClientProt::ANTICHEAT_OPLOGIC2, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatOp3)] +pub unsafe fn anticheatop3(bytes: Vec) -> Option { + return Some(AnticheatOp3::decode(ClientProt::ANTICHEAT_OPLOGIC3, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatOp4)] +pub unsafe fn anticheatop4(bytes: Vec) -> Option { + return Some(AnticheatOp4::decode(ClientProt::ANTICHEAT_OPLOGIC4, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatOp5)] +pub unsafe fn anticheatop5(bytes: Vec) -> Option { + return Some(AnticheatOp5::decode(ClientProt::ANTICHEAT_OPLOGIC5, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatOp6)] +pub unsafe fn anticheatop6(bytes: Vec) -> Option { + return Some(AnticheatOp6::decode(ClientProt::ANTICHEAT_OPLOGIC6, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatOp7)] +pub unsafe fn anticheatop7(bytes: Vec) -> Option { + return Some(AnticheatOp7::decode(ClientProt::ANTICHEAT_OPLOGIC7, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatOp8)] +pub unsafe fn anticheatop8(bytes: Vec) -> Option { + return Some(AnticheatOp8::decode(ClientProt::ANTICHEAT_OPLOGIC8, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatOp9)] +pub unsafe fn anticheatop9(bytes: Vec) -> Option { + return Some(AnticheatOp9::decode(ClientProt::ANTICHEAT_OPLOGIC9, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatCycle1)] +pub unsafe fn anticheatcycle1(bytes: Vec) -> Option { + return Some(AnticheatCycle1::decode(ClientProt::ANTICHEAT_CYCLELOGIC1, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatCycle2)] +pub unsafe fn anticheatcycle2(bytes: Vec) -> Option { + return Some(AnticheatCycle2::decode(ClientProt::ANTICHEAT_CYCLELOGIC2, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatCycle3)] +pub unsafe fn anticheatcycle3(bytes: Vec) -> Option { + return Some(AnticheatCycle3::decode(ClientProt::ANTICHEAT_CYCLELOGIC3, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatCycle4)] +pub unsafe fn anticheatcycle4(bytes: Vec) -> Option { + return Some(AnticheatCycle4::decode(ClientProt::ANTICHEAT_CYCLELOGIC4, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatCycle5)] +pub unsafe fn anticheatcycle5(bytes: Vec) -> Option { + return Some(AnticheatCycle5::decode(ClientProt::ANTICHEAT_CYCLELOGIC5, &mut read(bytes))); +} + +#[wasm_bindgen(js_name = anticheatCycle6)] +pub unsafe fn anticheatcycle6(bytes: Vec) -> Option { + return Some(AnticheatCycle6::decode(ClientProt::ANTICHEAT_CYCLELOGIC6, &mut read(bytes))); +} diff --git a/src/message.rs b/src/message.rs index 6581ca0..30b53a3 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,9 +1,70 @@ use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::{ClientProt, ServerInternalProt}; +use wasm_bindgen::prelude::wasm_bindgen; +use crate::coord::CoordGrid; pub trait InfoMessage { fn encode(&self, buf: &mut Packet); fn test(&self) -> usize; - fn persists(&self) -> bool; +} + +pub trait MessageEncoder { + fn id(&self) -> i32; + fn length(&self) -> i32; + fn priority(&self) -> ServerProtPriority; + fn encode(&self, buf: &mut Packet); + fn test(&self) -> usize; +} + +pub trait MessageDecoder { + fn length() -> i32; + fn decode(prot: ClientProt, buf: &mut Packet) -> T; +} + +#[wasm_bindgen] +#[derive(Clone)] // for VecDeque +pub struct OutgoingPacket { + #[wasm_bindgen(getter_with_clone, readonly)] + pub bytes: Option>, + #[wasm_bindgen(readonly)] + pub id: i32, + #[wasm_bindgen(readonly)] + pub length: i32, +} + +impl OutgoingPacket { + pub fn new( + bytes: Option>, + id: i32, + length: i32 + ) -> OutgoingPacket { + return OutgoingPacket { + bytes, + id, + length, + } + } +} + +#[wasm_bindgen] +pub struct IncomingPacket { + #[wasm_bindgen(readonly)] + pub id: i32, + #[wasm_bindgen(readonly)] + pub length: i32, +} + +impl IncomingPacket { + pub fn new( + id: i32, + length: i32 + ) -> IncomingPacket { + return IncomingPacket { + id, + length, + } + } } // ---- players @@ -32,11 +93,6 @@ impl InfoMessage for PlayerInfoAppearance { fn test(&self) -> usize { return 1 + self.bytes.len(); } - - #[inline] - fn persists(&self) -> bool { - return true; - } } // ---- @@ -64,11 +120,6 @@ impl InfoMessage for PlayerInfoFaceEntity { fn test(&self) -> usize { return 2; } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -102,11 +153,6 @@ impl InfoMessage for PlayerInfoFaceCoord { fn test(&self) -> usize { return 4; } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -140,11 +186,6 @@ impl InfoMessage for PlayerInfoAnim { fn test(&self) -> usize { return 3; } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -172,11 +213,6 @@ impl InfoMessage for PlayerInfoSay { fn test(&self) -> usize { return 1 + self.say.len(); } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -218,11 +254,6 @@ impl InfoMessage for PlayerInfoDamage { fn test(&self) -> usize { return 4; } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -265,11 +296,6 @@ impl InfoMessage for PlayerInfoChat { fn test(&self) -> usize { return 1 + 1 + 1 + 1 + self.bytes.len(); } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -306,11 +332,6 @@ impl InfoMessage for PlayerInfoSpotanim { fn test(&self) -> usize { return 6; } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -364,11 +385,6 @@ impl InfoMessage for PlayerInfoExactMove { fn test(&self) -> usize { return 9; } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- npcs @@ -396,11 +412,6 @@ impl InfoMessage for NpcInfoFaceEntity { fn test(&self) -> usize { return 2; } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -434,11 +445,6 @@ impl InfoMessage for NpcInfoFaceCoord { fn test(&self) -> usize { return 4; } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -472,11 +478,6 @@ impl InfoMessage for NpcInfoAnim { fn test(&self) -> usize { return 3; } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -504,11 +505,6 @@ impl InfoMessage for NpcInfoSay { fn test(&self) -> usize { return 1 + self.say.len(); } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -550,11 +546,6 @@ impl InfoMessage for NpcInfoDamage { fn test(&self) -> usize { return 4; } - - #[inline] - fn persists(&self) -> bool { - return false; - } } // ---- @@ -580,10 +571,6 @@ impl InfoMessage for NpcInfoChangeType { fn test(&self) -> usize { return 2; } - - fn persists(&self) -> bool { - return false; - } } // ---- @@ -620,11 +607,1986 @@ impl InfoMessage for NpcInfoSpotanim { fn test(&self) -> usize { return 6; } +} + +// ---- encoders + +pub struct IfOpenMain { + component: i32, +} + +impl IfOpenMain { + pub fn new(component:i32) -> IfOpenMain { + return IfOpenMain { + component, + } + } +} - #[inline] - fn persists(&self) -> bool { - return false; +impl MessageEncoder for IfOpenMain { + fn id(&self) -> i32 { + return ServerInternalProt::IF_OPENMAIN as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + } + + fn test(&self) -> usize { + return 2; + } +} + +// ---- + +pub struct IfOpenSide { + component: i32, +} + +impl IfOpenSide { + pub fn new(component:i32) -> IfOpenSide { + return IfOpenSide { + component, + } + } +} + +impl MessageEncoder for IfOpenSide { + fn id(&self) -> i32 { + return ServerInternalProt::IF_OPENSIDE as i32 + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + } + + fn test(&self) -> usize { + return 2; + } +} + +// ---- + +pub struct MessageGame { + msg: String, +} + +impl MessageGame { + pub fn new(msg: String) -> MessageGame { + return MessageGame { + msg, + } + } +} + +impl MessageEncoder for MessageGame { + fn id(&self) -> i32 { + return ServerInternalProt::MESSAGE_GAME as i32 + } + + fn length(&self) -> i32 { + return -1; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.pjstr(&self.msg, 10); + } + + fn test(&self) -> usize { + return 1 + self.msg.len(); } } -// ---- \ No newline at end of file +// ---- decoders + +#[wasm_bindgen] +pub struct ClientCheat { + #[wasm_bindgen(getter_with_clone, readonly)] + pub input: String, +} + +#[wasm_bindgen] +impl ClientCheat { + #[wasm_bindgen(constructor)] + pub fn new(input: String) -> ClientCheat { + return ClientCheat { + input, + } + } +} + +impl MessageDecoder for ClientCheat { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> ClientCheat { + return ClientCheat::new(buf.gjstr(10)); + } +} + +// ---- + +#[wasm_bindgen] +pub struct CloseModal {} + +#[wasm_bindgen] +impl CloseModal { + #[wasm_bindgen(constructor)] + pub fn new() -> CloseModal { + return CloseModal {} + } +} + +impl MessageDecoder for CloseModal { + fn length() -> i32 { + return 0; + } + + fn decode(_: ClientProt, _: &mut Packet) -> CloseModal { + return CloseModal::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct FriendListAdd { + #[wasm_bindgen(readonly)] + pub username: i64, +} + +#[wasm_bindgen] +impl FriendListAdd { + #[wasm_bindgen(constructor)] + pub fn new(username: i64) -> FriendListAdd { + return FriendListAdd { + username, + } + } +} + +impl MessageDecoder for FriendListAdd { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> FriendListAdd { + return FriendListAdd::new(buf.g8s()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct FriendListDel { + #[wasm_bindgen(readonly)] + pub username: i64, +} + +#[wasm_bindgen] +impl FriendListDel { + #[wasm_bindgen(constructor)] + pub fn new(username: i64) -> FriendListDel { + return FriendListDel { + username, + } + } +} + +impl MessageDecoder for FriendListDel { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> FriendListDel { + return FriendListDel::new(buf.g8s()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct IdleTimer {} + +#[wasm_bindgen] +impl IdleTimer { + #[wasm_bindgen(constructor)] + pub fn new() -> IdleTimer { + return IdleTimer {} + } +} + +impl MessageDecoder for IdleTimer { + fn length() -> i32 { + return 0; + } + + fn decode(_: ClientProt, _: &mut Packet) -> IdleTimer { + return IdleTimer::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct IfButton { + #[wasm_bindgen(readonly)] + pub component: u16, +} + +#[wasm_bindgen] +impl IfButton { + #[wasm_bindgen(constructor)] + pub fn new(component: u16) -> IfButton { + return IfButton { + component, + } + } +} + +impl MessageDecoder for IfButton { + fn length() -> i32 { + return 2; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> IfButton { + return IfButton::new(buf.g2()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct IfPlayerDesign { + #[wasm_bindgen(readonly)] + pub gender: u8, + #[wasm_bindgen(getter_with_clone, readonly)] + pub idkit: Vec, + #[wasm_bindgen(getter_with_clone, readonly)] + pub color: Vec, +} + +#[wasm_bindgen] +impl IfPlayerDesign { + #[wasm_bindgen(constructor)] + pub fn new(gender: u8, idkit: Vec, color: Vec) -> IfPlayerDesign { + return IfPlayerDesign { + gender, + idkit, + color, + } + } +} + +impl MessageDecoder for IfPlayerDesign { + fn length() -> i32 { + return 13; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> IfPlayerDesign { + let gender: u8 = buf.g1(); + + let mut idkit: [i32; 7] = [0; 7]; + for i in 0..7 { + let mut v = buf.g1() as i32; + if v == 0xff { + v = -1; + } + unsafe { *idkit.as_mut_ptr().add(i as usize) = v }; + } + + let mut color: [i32; 5] = [0; 5]; + for i in 0..5 { + unsafe { *color.as_mut_ptr().add(i as usize) = buf.g1() as i32 }; + } + + return IfPlayerDesign::new(gender, idkit.to_vec(), color.to_vec()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct IgnoreListAdd { + #[wasm_bindgen(readonly)] + pub username: i64, +} + +#[wasm_bindgen] +impl IgnoreListAdd { + #[wasm_bindgen(constructor)] + pub fn new(username: i64) -> IgnoreListAdd { + return IgnoreListAdd { + username, + } + } +} + +impl MessageDecoder for IgnoreListAdd { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> IgnoreListAdd { + return IgnoreListAdd::new(buf.g8s()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct IgnoreListDel { + #[wasm_bindgen(readonly)] + pub username: i64, +} + +#[wasm_bindgen] +impl IgnoreListDel { + #[wasm_bindgen(constructor)] + pub fn new(username: i64) -> IgnoreListDel { + return IgnoreListDel { + username, + } + } +} + +impl MessageDecoder for IgnoreListDel { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> IgnoreListDel { + return IgnoreListDel::new(buf.g8s()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct InvButton { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly)] + pub slot: u16, + #[wasm_bindgen(readonly)] + pub component: u16, +} + +#[wasm_bindgen] +impl InvButton { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + obj: u16, + slot: u16, + component: u16, + ) -> InvButton { + return InvButton { + op, + obj, + slot, + component, + } + } +} + +impl MessageDecoder for InvButton { + fn length() -> i32 { + return 6; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> InvButton { + let op: u8 = match prot { + ClientProt::INV_BUTTON1 => 1, + ClientProt::INV_BUTTON2 => 2, + ClientProt::INV_BUTTON3 => 3, + ClientProt::INV_BUTTON4 => 4, + ClientProt::INV_BUTTON5 => 5, + _ => 0, + }; + return InvButton::new( + op, + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct InvButtonD { + #[wasm_bindgen(readonly)] + pub component: u16, + #[wasm_bindgen(readonly)] + pub slot: u16, + #[wasm_bindgen(readonly)] + pub target: u16, +} + +#[wasm_bindgen] +impl InvButtonD { + #[wasm_bindgen(constructor)] + pub fn new( + component: u16, + slot: u16, + target: u16, + ) -> InvButtonD { + return InvButtonD { + component, + slot, + target, + } + } +} + +impl MessageDecoder for InvButtonD { + fn length() -> i32 { + return 6; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> InvButtonD { + return InvButtonD::new( + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct MessagePrivate { + #[wasm_bindgen(readonly)] + pub username: i64, + #[wasm_bindgen(getter_with_clone, readonly)] + pub input: Vec, +} + +#[wasm_bindgen] +impl MessagePrivate { + #[wasm_bindgen(constructor)] + pub fn new( + username: i64, + input: Vec, + ) -> MessagePrivate { + return MessagePrivate { + username, + input, + } + } +} + +impl MessageDecoder for MessagePrivate { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> MessagePrivate { + return MessagePrivate::new( + buf.g8s(), + unsafe { buf.data.get_unchecked(buf.pos..buf.pos + buf.data.len() - 8).to_vec() } + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct MessagePublic { + #[wasm_bindgen(readonly)] + pub color: u8, + #[wasm_bindgen(readonly)] + pub effect: u8, + #[wasm_bindgen(getter_with_clone, readonly)] + pub input: Vec, +} + +#[wasm_bindgen] +impl MessagePublic { + #[wasm_bindgen(constructor)] + pub fn new( + color: u8, + effect: u8, + input: Vec, + ) -> MessagePublic { + return MessagePublic { + color, + effect, + input, + } + } +} + +impl MessageDecoder for MessagePublic { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> MessagePublic { + return MessagePublic::new( + buf.g1(), + buf.g1(), + unsafe { buf.data.get_unchecked(buf.pos..buf.pos + buf.data.len() - 2).to_vec() } + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct MoveClick { + #[wasm_bindgen(readonly)] + pub ctrl: bool, + #[wasm_bindgen(readonly)] + pub op: bool, + #[wasm_bindgen(getter_with_clone, readonly)] + pub path: Vec, +} + +#[wasm_bindgen] +impl MoveClick { + #[wasm_bindgen(constructor)] + pub fn new( + ctrl: bool, + op: bool, + path: Vec, + ) -> MoveClick { + return MoveClick { + ctrl, + op, + path, + } + } +} + +impl MessageDecoder for MoveClick { + fn length() -> i32 { + return -1; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> MoveClick { + let ctrl: bool = buf.g1() == 1; + let x: u16 = buf.g2(); + let z: u16 = buf.g2(); + + let offset: usize = if prot == ClientProt::MOVE_MINIMAPCLICK { 14 } else { 0 }; + let waypoints: usize = ((buf.data.len() - buf.pos - offset) / 2) + 1; + + let mut path: Vec = vec![0; waypoints]; + path[0] = CoordGrid::from(x, 0, z).packed; + + for index in 1..waypoints { + if index >= 25 { + break; + } + unsafe { *path.as_mut_ptr().add(index) = CoordGrid::from(x + buf.g1s() as u16, 0, z + buf.g1s() as u16).packed }; + } + + return MoveClick::new( + ctrl, + prot == ClientProt::MOVE_OPCLICK, + path, + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct NoTimeout {} + +#[wasm_bindgen] +impl NoTimeout { + #[wasm_bindgen(constructor)] + pub fn new() -> NoTimeout { + return NoTimeout {}; + } +} + +impl MessageDecoder for NoTimeout { + fn length() -> i32 { + return 0; + } + + fn decode(_: ClientProt, _: &mut Packet) -> NoTimeout { + return NoTimeout::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpHeld { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly)] + pub slot: u16, + #[wasm_bindgen(readonly)] + pub component: u16, +} + +#[wasm_bindgen] +impl OpHeld { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + obj: u16, + slot: u16, + component: u16, + ) -> OpHeld { + return OpHeld { + op, + obj, + slot, + component, + } + } +} + +impl MessageDecoder for OpHeld { + fn length() -> i32 { + return 6; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> OpHeld { + let op: u8 = match prot { + ClientProt::OPHELD1 => 1, + ClientProt::OPHELD2 => 2, + ClientProt::OPHELD3 => 3, + ClientProt::OPHELD4 => 4, + ClientProt::OPHELD5 => 5, + _ => 0, + }; + return OpHeld::new( + op, + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpHeldT { + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly)] + pub slot: u16, + #[wasm_bindgen(readonly)] + pub component: u16, + #[wasm_bindgen(readonly)] + pub spell: u16, +} + +#[wasm_bindgen] +impl OpHeldT { + #[wasm_bindgen(constructor)] + pub fn new( + obj: u16, + slot: u16, + component: u16, + spell: u16, + ) -> OpHeldT { + return OpHeldT { + obj, + slot, + component, + spell, + } + } +} + +impl MessageDecoder for OpHeldT { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpHeldT { + return OpHeldT::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpHeldU { + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly)] + pub slot: u16, + #[wasm_bindgen(readonly)] + pub component: u16, + #[wasm_bindgen(readonly, js_name = useObj)] + pub use_obj: u16, + #[wasm_bindgen(readonly, js_name = useSlot)] + pub use_slot: u16, + #[wasm_bindgen(readonly, js_name = useComponent)] + pub use_component: u16, +} + +#[wasm_bindgen] +impl OpHeldU { + #[wasm_bindgen(constructor)] + pub fn new( + obj: u16, + slot: u16, + component: u16, + use_obj: u16, + use_slot: u16, + use_component: u16, + ) -> OpHeldU { + return OpHeldU { + obj, + slot, + component, + use_obj, + use_slot, + use_component, + } + } +} + +impl MessageDecoder for OpHeldU { + fn length() -> i32 { + return 12; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpHeldU { + return OpHeldU::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpLoc { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub loc: u16, +} + +#[wasm_bindgen] +impl OpLoc { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + x: u16, + z: u16, + loc: u16, + ) -> OpLoc { + return OpLoc { + op, + x, + z, + loc, + } + } +} + +impl MessageDecoder for OpLoc { + fn length() -> i32 { + return 6; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> OpLoc { + let op: u8 = match prot { + ClientProt::OPLOC1 => 1, + ClientProt::OPLOC2 => 2, + ClientProt::OPLOC3 => 3, + ClientProt::OPLOC4 => 4, + ClientProt::OPLOC5 => 5, + _ => 0, + }; + return OpLoc::new( + op, + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpLocT { + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub loc: u16, + #[wasm_bindgen(readonly)] + pub spell: u16, +} + +#[wasm_bindgen] +impl OpLocT { + #[wasm_bindgen(constructor)] + pub fn new( + x: u16, + z: u16, + loc: u16, + spell: u16, + ) -> OpLocT { + return OpLocT { + x, + z, + loc, + spell, + } + } +} + +impl MessageDecoder for OpLocT { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpLocT { + return OpLocT::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpLocU { + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub loc: u16, + #[wasm_bindgen(readonly, js_name = useObj)] + pub use_obj: u16, + #[wasm_bindgen(readonly, js_name = useSlot)] + pub use_slot: u16, + #[wasm_bindgen(readonly, js_name = useComponent)] + pub use_component: u16, +} + +#[wasm_bindgen] +impl OpLocU { + #[wasm_bindgen(constructor)] + pub fn new( + x: u16, + z: u16, + loc: u16, + use_obj: u16, + use_slot: u16, + use_component: u16, + ) -> OpLocU { + return OpLocU { + x, + z, + loc, + use_obj, + use_slot, + use_component, + } + } +} + +impl MessageDecoder for OpLocU { + fn length() -> i32 { + return 12; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpLocU { + return OpLocU::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpNpc { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub nid: u16, +} + +#[wasm_bindgen] +impl OpNpc { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + nid: u16, + ) -> OpNpc { + return OpNpc { + op, + nid, + } + } +} + +impl MessageDecoder for OpNpc { + fn length() -> i32 { + return 2; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> OpNpc { + let op: u8 = match prot { + ClientProt::OPNPC1 => 1, + ClientProt::OPNPC2 => 2, + ClientProt::OPNPC3 => 3, + ClientProt::OPNPC4 => 4, + ClientProt::OPNPC5 => 5, + _ => 0, + }; + return OpNpc::new( + op, + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpNpcT { + #[wasm_bindgen(readonly)] + pub nid: u16, + #[wasm_bindgen(readonly)] + pub spell: u16, +} + +#[wasm_bindgen] +impl OpNpcT { + #[wasm_bindgen(constructor)] + pub fn new( + nid: u16, + spell: u16, + ) -> OpNpcT { + return OpNpcT { + nid, + spell, + } + } +} + +impl MessageDecoder for OpNpcT { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpNpcT { + return OpNpcT::new( + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpNpcU { + #[wasm_bindgen(readonly)] + pub nid: u16, + #[wasm_bindgen(readonly, js_name = useObj)] + pub use_obj: u16, + #[wasm_bindgen(readonly, js_name = useSlot)] + pub use_slot: u16, + #[wasm_bindgen(readonly, js_name = useComponent)] + pub use_component: u16, +} + +#[wasm_bindgen] +impl OpNpcU { + #[wasm_bindgen(constructor)] + pub fn new( + nid: u16, + use_obj: u16, + use_slot: u16, + use_component: u16, + ) -> OpNpcU { + return OpNpcU { + nid, + use_obj, + use_slot, + use_component, + } + } +} + +impl MessageDecoder for OpNpcU { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpNpcU { + return OpNpcU::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpObj { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub obj: u16, +} + +#[wasm_bindgen] +impl OpObj { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + x: u16, + z: u16, + obj: u16, + ) -> OpObj { + return OpObj { + op, + x, + z, + obj, + } + } +} + +impl MessageDecoder for OpObj { + fn length() -> i32 { + return 6; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> OpObj { + let op: u8 = match prot { + ClientProt::OPOBJ1 => 1, + ClientProt::OPOBJ2 => 2, + ClientProt::OPOBJ3 => 3, + ClientProt::OPOBJ4 => 4, + ClientProt::OPOBJ5 => 5, + _ => 0, + }; + return OpObj::new( + op, + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpObjT { + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly)] + pub spell: u16, +} + +#[wasm_bindgen] +impl OpObjT { + #[wasm_bindgen(constructor)] + pub fn new( + x: u16, + z: u16, + obj: u16, + spell: u16, + ) -> OpObjT { + return OpObjT { + x, + z, + obj, + spell, + } + } +} + +impl MessageDecoder for OpObjT { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpObjT { + return OpObjT::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpObjU { + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly, js_name = useObj)] + pub use_obj: u16, + #[wasm_bindgen(readonly, js_name = useSlot)] + pub use_slot: u16, + #[wasm_bindgen(readonly, js_name = useComponent)] + pub use_component: u16, +} + +#[wasm_bindgen] +impl OpObjU { + #[wasm_bindgen(constructor)] + pub fn new( + x: u16, + z: u16, + obj: u16, + use_obj: u16, + use_slot: u16, + use_component: u16, + ) -> OpObjU { + return OpObjU { + x, + z, + obj, + use_obj, + use_slot, + use_component, + } + } +} + +impl MessageDecoder for OpObjU { + fn length() -> i32 { + return 12; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpObjU { + return OpObjU::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpPlayer { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub pid: u16, +} + +#[wasm_bindgen] +impl OpPlayer { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + pid: u16, + ) -> OpPlayer { + return OpPlayer { + op, + pid, + } + } +} + +impl MessageDecoder for OpPlayer { + fn length() -> i32 { + return 2; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> OpPlayer { + let op: u8 = match prot { + ClientProt::OPPLAYER1 => 1, + ClientProt::OPPLAYER2 => 2, + ClientProt::OPPLAYER3 => 3, + ClientProt::OPPLAYER4 => 4, + _ => 0, + }; + return OpPlayer::new( + op, + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpPlayerT { + #[wasm_bindgen(readonly)] + pub pid: u16, + #[wasm_bindgen(readonly)] + pub spell: u16, +} + +#[wasm_bindgen] +impl OpPlayerT { + #[wasm_bindgen(constructor)] + pub fn new( + pid: u16, + spell: u16, + ) -> OpPlayerT { + return OpPlayerT { + pid, + spell, + } + } +} + +impl MessageDecoder for OpPlayerT { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpPlayerT { + return OpPlayerT::new( + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpPlayerU { + #[wasm_bindgen(readonly)] + pub pid: u16, + #[wasm_bindgen(readonly, js_name = useObj)] + pub use_obj: u16, + #[wasm_bindgen(readonly, js_name = useSlot)] + pub use_slot: u16, + #[wasm_bindgen(readonly, js_name = useComponent)] + pub use_component: u16, +} + +#[wasm_bindgen] +impl OpPlayerU { + #[wasm_bindgen(constructor)] + pub fn new( + pid: u16, + use_obj: u16, + use_slot: u16, + use_component: u16, + ) -> OpPlayerU { + return OpPlayerU { + pid, + use_obj, + use_slot, + use_component, + } + } +} + +impl MessageDecoder for OpPlayerU { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpPlayerU { + return OpPlayerU::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct RebuildGetMaps { + #[wasm_bindgen(getter_with_clone, readonly)] + pub maps: Vec, +} + +#[wasm_bindgen] +impl RebuildGetMaps { + #[wasm_bindgen(constructor)] + pub fn new(maps: Vec) -> RebuildGetMaps { + return RebuildGetMaps { + maps, + } + } +} + +impl MessageDecoder for RebuildGetMaps { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> RebuildGetMaps { + let mut maps: Vec = vec![0; buf.data.len() / 3]; + for index in 0..maps.len() { + unsafe { *maps.as_mut_ptr().add(index) = buf.g3() as u32 }; + } + return RebuildGetMaps::new(maps); + } +} + +// ---- + +#[wasm_bindgen] +pub struct ResumePauseButton { + #[wasm_bindgen(readonly)] + pub component: u16, +} + +#[wasm_bindgen] +impl ResumePauseButton { + pub fn new(component: u16) -> ResumePauseButton { + return ResumePauseButton { + component, + }; + } +} + +impl MessageDecoder for ResumePauseButton { + fn length() -> i32 { + return 2; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> ResumePauseButton { + return ResumePauseButton::new(buf.g2()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct ResumePCountDialog { + #[wasm_bindgen(readonly)] + pub input: i32, +} + +#[wasm_bindgen] +impl ResumePCountDialog { + #[wasm_bindgen(constructor)] + pub fn new(input: i32) -> ResumePCountDialog { + return ResumePCountDialog { + input, + } + } +} + +impl MessageDecoder for ResumePCountDialog { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> ResumePCountDialog { + return ResumePCountDialog::new(buf.g4s()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct TutorialClickSide { + #[wasm_bindgen(readonly)] + pub tab: u8, +} + +#[wasm_bindgen] +impl TutorialClickSide { + #[wasm_bindgen(constructor)] + pub fn new(tab: u8) -> TutorialClickSide { + return TutorialClickSide { + tab, + } + } +} + +impl MessageDecoder for TutorialClickSide { + fn length() -> i32 { + return 1; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> TutorialClickSide { + return TutorialClickSide::new(buf.g1()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct ChatSetMode { + #[wasm_bindgen(readonly)] + pub public: u8, + #[wasm_bindgen(readonly)] + pub private: u8, + #[wasm_bindgen(readonly)] + pub trade: u8, +} + +#[wasm_bindgen] +impl ChatSetMode { + #[wasm_bindgen(constructor)] + pub fn new( + public: u8, + private: u8, + trade: u8, + ) -> ChatSetMode { + return ChatSetMode { + public, + private, + trade, + } + } +} + +impl MessageDecoder for ChatSetMode { + fn length() -> i32 { + return 3; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> ChatSetMode { + return ChatSetMode::new( + buf.g1(), + buf.g1(), + buf.g1(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct EventTracking { + #[wasm_bindgen(getter_with_clone, readonly)] + pub bytes: Vec, +} + +#[wasm_bindgen] +impl EventTracking { + #[wasm_bindgen(constructor)] + pub fn new(bytes: Vec) -> EventTracking { + return EventTracking { + bytes, + } + } +} + +impl MessageDecoder for EventTracking { + fn length() -> i32 { + return -2; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> EventTracking { + return EventTracking::new(buf.data.clone()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct ReportAbuse { + #[wasm_bindgen(readonly)] + pub offender: i64, + #[wasm_bindgen(readonly)] + pub reason: u8, + #[wasm_bindgen(readonly)] + pub mute: bool, +} + +#[wasm_bindgen] +impl ReportAbuse { + pub fn new( + offender: i64, + reason: u8, + mute: bool, + ) -> ReportAbuse { + return ReportAbuse { + offender, + reason, + mute, + } + } +} + +impl MessageDecoder for ReportAbuse { + fn length() -> i32 { + return 10; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> ReportAbuse { + return ReportAbuse::new( + buf.g8s(), + buf.g1(), + buf.g1() == 1, + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct EventCameraPosition { + #[wasm_bindgen(readonly)] + pub pitch: i32, + #[wasm_bindgen(readonly)] + pub yaw: i32, + #[wasm_bindgen(readonly)] + pub angle: i32, + #[wasm_bindgen(readonly)] + pub zoom: i32, +} + +#[wasm_bindgen] +impl EventCameraPosition { + #[wasm_bindgen(constructor)] + pub fn new( + pitch: i32, + yaw: i32, + angle: i32, + zoom: i32, + ) -> EventCameraPosition { + return EventCameraPosition { + pitch, + yaw, + angle, + zoom, + } + } +} + +impl MessageDecoder for EventCameraPosition { + fn length() -> i32 { + return 6; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> EventCameraPosition { + return EventCameraPosition::new( + buf.g2() as i32, + buf.g2() as i32, + buf.g1() as i32, + buf.g1() as i32, + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp1 {} + +#[wasm_bindgen] +impl AnticheatOp1 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp1 { + return AnticheatOp1 {}; + } +} + +impl MessageDecoder for AnticheatOp1 { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp1 { + return AnticheatOp1::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp2 {} + +#[wasm_bindgen] +impl AnticheatOp2 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp2 { + return AnticheatOp2 {}; + } +} + +impl MessageDecoder for AnticheatOp2 { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp2 { + return AnticheatOp2::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp3 {} + +#[wasm_bindgen] +impl AnticheatOp3 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp3 { + return AnticheatOp3 {}; + } +} + +impl MessageDecoder for AnticheatOp3 { + fn length() -> i32 { + return 3; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp3 { + return AnticheatOp3::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp4 {} + +#[wasm_bindgen] +impl AnticheatOp4 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp4 { + return AnticheatOp4 {}; + } +} + +impl MessageDecoder for AnticheatOp4 { + fn length() -> i32 { + return 2; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp4 { + return AnticheatOp4::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp5 {} + +#[wasm_bindgen] +impl AnticheatOp5 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp5 { + return AnticheatOp5 {}; + } +} + +impl MessageDecoder for AnticheatOp5 { + fn length() -> i32 { + return 0; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp5 { + return AnticheatOp5::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp6 {} + +#[wasm_bindgen] +impl AnticheatOp6 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp6 { + return AnticheatOp6 {}; + } +} + +impl MessageDecoder for AnticheatOp6 { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp6 { + return AnticheatOp6::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp7 {} + +#[wasm_bindgen] +impl AnticheatOp7 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp7 { + return AnticheatOp7 {}; + } +} + +impl MessageDecoder for AnticheatOp7 { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp7 { + return AnticheatOp7::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp8 {} + +#[wasm_bindgen] +impl AnticheatOp8 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp8 { + return AnticheatOp8 {}; + } +} + +impl MessageDecoder for AnticheatOp8 { + fn length() -> i32 { + return 2; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp8 { + return AnticheatOp8::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp9 {} + +#[wasm_bindgen] +impl AnticheatOp9 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp9 { + return AnticheatOp9 {}; + } +} + +impl MessageDecoder for AnticheatOp9 { + fn length() -> i32 { + return 1; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp9 { + return AnticheatOp9::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle1 {} + +#[wasm_bindgen] +impl AnticheatCycle1 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle1 { + return AnticheatCycle1 {}; + } +} + +impl MessageDecoder for AnticheatCycle1 { + fn length() -> i32 { + return 1; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle1 { + return AnticheatCycle1::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle2 {} + +#[wasm_bindgen] +impl AnticheatCycle2 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle2 { + return AnticheatCycle2 {}; + } +} + +impl MessageDecoder for AnticheatCycle2 { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle2 { + return AnticheatCycle2::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle3 {} + +#[wasm_bindgen] +impl AnticheatCycle3 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle3 { + return AnticheatCycle3 {}; + } +} + +impl MessageDecoder for AnticheatCycle3 { + fn length() -> i32 { + return 3; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle3 { + return AnticheatCycle3::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle4 {} + +#[wasm_bindgen] +impl AnticheatCycle4 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle4 { + return AnticheatCycle4 {}; + } +} + +impl MessageDecoder for AnticheatCycle4 { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle4 { + return AnticheatCycle4::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle5 {} + +#[wasm_bindgen] +impl AnticheatCycle5 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle5 { + return AnticheatCycle5 {}; + } +} + +impl MessageDecoder for AnticheatCycle5 { + fn length() -> i32 { + return 0; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle5 { + return AnticheatCycle5::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle6 {} + +#[wasm_bindgen] +impl AnticheatCycle6 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle6 { + return AnticheatCycle6 {}; + } +} + +impl MessageDecoder for AnticheatCycle6 { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle6 { + return AnticheatCycle6::new(); + } +} \ No newline at end of file diff --git a/src/player.rs b/src/player.rs index 72ec4fb..f37acb8 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,6 +1,10 @@ use crate::build::BuildArea; use crate::coord::CoordGrid; +use crate::message::{MessageEncoder, OutgoingPacket}; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; use crate::visibility::Visibility; +use std::collections::VecDeque; #[derive(Clone)] pub struct Player { @@ -34,6 +38,7 @@ pub struct Player { pub graphic_height: i32, pub graphic_delay: i32, pub exact_move: Option, + pub write_queue: VecDeque, } #[derive(Clone)] @@ -89,9 +94,24 @@ impl Player { graphic_height: -1, graphic_delay: -1, exact_move: None, + write_queue: VecDeque::new(), } } + #[inline] + pub fn write(&mut self, message: &dyn MessageEncoder) -> Option { + let mut buf: Packet = Packet::new(message.test()); + message.encode(&mut buf); + let out: OutgoingPacket = OutgoingPacket::new(Some(buf.data), message.id(), message.length()); + return match message.priority() { + ServerProtPriority::Buffered => { + self.write_queue.push_back(out); + return None; + }, + ServerProtPriority::Immediate => Some(out), + }; + } + #[inline] pub fn cleanup(&mut self) { self.walk_dir = -1; @@ -118,6 +138,7 @@ impl Player { self.graphic_height = -1; self.graphic_delay = -1; self.exact_move = None; + self.write_queue.clear(); } } diff --git a/src/priority.rs b/src/priority.rs new file mode 100644 index 0000000..007e167 --- /dev/null +++ b/src/priority.rs @@ -0,0 +1,12 @@ +// these priorities are important for cases where the content developer wants to be aware of the +// bandwidth implications their script may run into and how it impacts the player experience +#[repr(u8)] +pub enum ServerProtPriority { + // counted as part of the buffer_full command + // alternate names: LOW, CONTENT + Buffered, + + // not counted as part of the buffer_full command + // alternate names: HIGH, ESSENTIAL, ENGINE + Immediate, +} \ No newline at end of file diff --git a/src/prot.rs b/src/prot.rs index c106204..f5cb121 100644 --- a/src/prot.rs +++ b/src/prot.rs @@ -3,7 +3,7 @@ use wasm_bindgen::prelude::wasm_bindgen; #[repr(u16)] -#[derive(Eq, Hash, PartialEq)] +#[derive(PartialEq)] #[wasm_bindgen] pub enum PlayerInfoProt { APPEARANCE = 0x1, @@ -38,7 +38,6 @@ impl PlayerInfoProt { } #[repr(u16)] -#[derive(Eq, Hash, PartialEq)] #[wasm_bindgen] pub enum NpcInfoProt { ANIM = 0x2, @@ -64,4 +63,288 @@ impl NpcInfoProt { NpcInfoProt::FACE_COORD => 6, } } +} + +#[repr(u8)] +#[wasm_bindgen] +#[derive(PartialEq)] +pub enum ClientProt { + REBUILD_GETMAPS, + + NO_TIMEOUT, + + IDLE_TIMER, + + EVENT_TRACKING, + EVENT_CAMERA_POSITION, + + ANTICHEAT_OPLOGIC1, + ANTICHEAT_OPLOGIC2, + ANTICHEAT_OPLOGIC3, + ANTICHEAT_OPLOGIC4, + ANTICHEAT_OPLOGIC5, + ANTICHEAT_OPLOGIC6, + ANTICHEAT_OPLOGIC7, + ANTICHEAT_OPLOGIC8, + ANTICHEAT_OPLOGIC9, + + ANTICHEAT_CYCLELOGIC1, + ANTICHEAT_CYCLELOGIC2, + ANTICHEAT_CYCLELOGIC3, + ANTICHEAT_CYCLELOGIC4, + ANTICHEAT_CYCLELOGIC5, + ANTICHEAT_CYCLELOGIC6, + + OPOBJ1, + OPOBJ2, + OPOBJ3, + OPOBJ4, + OPOBJ5, + OPOBJT, + OPOBJU, + + OPNPC1, + OPNPC2, + OPNPC3, + OPNPC4, + OPNPC5, + OPNPCT, + OPNPCU, + + OPLOC1, + OPLOC2, + OPLOC3, + OPLOC4, + OPLOC5, + OPLOCT, + OPLOCU, + + OPPLAYER1, + OPPLAYER2, + OPPLAYER3, + OPPLAYER4, + OPPLAYERT, + OPPLAYERU, + + OPHELD1, + OPHELD2, + OPHELD3, + OPHELD4, + OPHELD5, + OPHELDT, + OPHELDU, + + INV_BUTTON1, + INV_BUTTON2, + INV_BUTTON3, + INV_BUTTON4, + INV_BUTTON5, + IF_BUTTON, + + RESUME_PAUSEBUTTON, + CLOSE_MODAL, + RESUME_P_COUNTDIALOG, + TUTORIAL_CLICKSIDE, + + MOVE_OPCLICK, + REPORT_ABUSE, + MOVE_MINIMAPCLICK, + INV_BUTTOND, + IGNORELIST_DEL, + IGNORELIST_ADD, + IF_PLAYERDESIGN, + CHAT_SETMODE, + MESSAGE_PRIVATE, + FRIENDLIST_DEL, + FRIENDLIST_ADD, + CLIENT_CHEAT, + MESSAGE_PUBLIC, + MOVE_GAMECLICK, +} + +#[repr(u8)] +pub enum ServerInternalProt { + // interfaces + IF_OPENCHAT = 14, + IF_OPENMAIN_SIDE = 28, + IF_CLOSE = 129, + IF_SETTAB = 167, + IF_OPENMAIN = 168, + IF_OPENSIDE = 195, + + // updating interfaces + IF_SETCOLOUR = 2, // NXT naming + IF_SETHIDE = 26, // NXT naming + IF_SETOBJECT = 46, // NXT naming + IF_SETTAB_ACTIVE = 84, + IF_SETMODEL = 87, // NXT naming + IF_SETRECOL = 103, // NXT naming + IF_SETANIM = 146, // NXT naming + IF_SETPLAYERHEAD = 197, // NXT naming + IF_SETTEXT = 201, // NXT naming + IF_SETNPCHEAD = 204, // NXT naming + IF_SETPOSITION = 209, // NXT naming + + // tutorial area + TUT_FLASH = 126, + TUT_OPEN = 185, + + // inventory + UPDATE_INV_STOP_TRANSMIT = 15, // NXT naming + UPDATE_INV_FULL = 98, // NXT naming + UPDATE_INV_PARTIAL = 213, // NXT naming + + // camera control + CAM_LOOKAT = 74, // NXT naming + CAM_SHAKE = 13, // NXT naming + CAM_MOVETO = 3, // NXT naming + CAM_RESET = 239, // NXT naming + + // entity updates + NPC_INFO = 1, // NXT naming + PLAYER_INFO = 184, // NXT naming + + // input tracking + FINISH_TRACKING = 133, + ENABLE_TRACKING = 226, + + // social + MESSAGE_GAME = 4, // NXT naming + UPDATE_IGNORELIST = 21, // NXT naming + CHAT_FILTER_SETTINGS = 32, // NXT naming + MESSAGE_PRIVATE = 41, // NXT naming + UPDATE_FRIENDLIST = 152, // NXT naming + + // misc + UNSET_MAP_FLAG = 19, // NXT has "SET_MAP_FLAG" but we cannot control the position + UPDATE_RUNWEIGHT = 22, // NXT naming + HINT_ARROW = 25, // NXT naming + UPDATE_REBOOT_TIMER = 43, // NXT naming + UPDATE_STAT = 44, // NXT naming + UPDATE_RUNENERGY = 68, // NXT naming + RESET_ANIMS = 136, // NXT naming + UPDATE_PID = 139, + LAST_LOGIN_INFO = 140, // NXT naming + LOGOUT = 142, // NXT naming + P_COUNTDIALOG = 243, // named after runescript command + client resume_p_countdialog packet + SET_MULTIWAY = 254, + + // maps + DATA_LOC_DONE = 20, + DATA_LAND_DONE = 80, + DATA_LAND = 132, + DATA_LOC = 220, + REBUILD_NORMAL = 237, // NXT naming (do we really need _normal if there's no region rebuild?) + + // vars + VARP_SMALL = 150, // NXT naming + VARP_LARGE = 175, // NXT naming + RESET_CLIENT_VARCACHE = 193, // NXT naming + + // audio + SYNTH_SOUND = 12, // NXT naming + MIDI_SONG = 54, // NXT naming + MIDI_JINGLE = 212, // NXT naming + + // zones + UPDATE_ZONE_PARTIAL_FOLLOWS = 7, // NXT naming + UPDATE_ZONE_FULL_FOLLOWS = 135, // NXT naming + UPDATE_ZONE_PARTIAL_ENCLOSED = 162, // NXT naming +} + +#[repr(u8)] +pub enum ClientInternalProt { + REBUILD_GETMAPS = 150, + + NO_TIMEOUT = 108, // NXT naming + + IDLE_TIMER = 70, + + EVENT_TRACKING = 81, + EVENT_CAMERA_POSITION = 189, // NXT naming + + // autogenerated as part of obfuscation process + ANTICHEAT_OPLOGIC1 = 7, + ANTICHEAT_OPLOGIC2 = 88, + ANTICHEAT_OPLOGIC3 = 30, + ANTICHEAT_OPLOGIC4 = 176, + ANTICHEAT_OPLOGIC5 = 220, + ANTICHEAT_OPLOGIC6 = 66, + ANTICHEAT_OPLOGIC7 = 17, + ANTICHEAT_OPLOGIC8 = 2, + ANTICHEAT_OPLOGIC9 = 238, + + // autogenerated as part of obfuscation process + ANTICHEAT_CYCLELOGIC1 = 233, + ANTICHEAT_CYCLELOGIC2 = 146, + ANTICHEAT_CYCLELOGIC3 = 215, + ANTICHEAT_CYCLELOGIC4 = 236, + ANTICHEAT_CYCLELOGIC5 = 85, + ANTICHEAT_CYCLELOGIC6 = 219, + + OPOBJ1 = 140, // NXT naming + OPOBJ2 = 40, // NXT naming + OPOBJ3 = 200, // NXT naming + OPOBJ4 = 178, // NXT naming + OPOBJ5 = 247, // NXT naming + OPOBJT = 138, // NXT naming + OPOBJU = 239, // NXT naming + + OPNPC1 = 194, // NXT naming + OPNPC2 = 8, // NXT naming + OPNPC3 = 27, // NXT naming + OPNPC4 = 113, // NXT naming + OPNPC5 = 100, // NXT naming + OPNPCT = 134, // NXT naming + OPNPCU = 202, // NXT naming + + OPLOC1 = 245, // NXT naming + OPLOC2 = 172, // NXT naming + OPLOC3 = 96, // NXT naming + OPLOC4 = 97, // NXT naming + OPLOC5 = 116, // NXT naming + OPLOCT = 9, // NXT naming + OPLOCU = 75, // NXT naming + + OPPLAYER1 = 164, // NXT naming + OPPLAYER2 = 53, // NXT naming + OPPLAYER3 = 185, // NXT naming + OPPLAYER4 = 206, // NXT naming + OPPLAYERT = 177, // NXT naming + OPPLAYERU = 248, // NXT naming + + OPHELD1 = 195, // name based on runescript trigger + OPHELD2 = 71, // name based on runescript trigger + OPHELD3 = 133, // name based on runescript trigger + OPHELD4 = 157, // name based on runescript trigger + OPHELD5 = 211, // name based on runescript trigger + OPHELDT = 48, // name based on runescript trigger + OPHELDU = 130, // name based on runescript trigger + + INV_BUTTON1 = 31, // NXT has "IF_BUTTON1" but for our interface system, this makes more sense + INV_BUTTON2 = 59, // NXT has "IF_BUTTON2" but for our interface system, this makes more sense + INV_BUTTON3 = 212, // NXT has "IF_BUTTON3" but for our interface system, this makes more sense + INV_BUTTON4 = 38, // NXT has "IF_BUTTON4" but for our interface system, this makes more sense + INV_BUTTON5 = 6, // NXT has "IF_BUTTON5" but for our interface system, this makes more sense + IF_BUTTON = 155, // NXT naming + + RESUME_PAUSEBUTTON = 235, // NXT naming + CLOSE_MODAL = 231, // NXT naming + RESUME_P_COUNTDIALOG = 237, // NXT naming + TUTORIAL_CLICKSIDE = 175, + + MOVE_OPCLICK = 93, // comes with OP packets, name based on other MOVE packets + REPORT_ABUSE = 190, + MOVE_MINIMAPCLICK = 165, // NXT naming + INV_BUTTOND = 159, // NXT has "IF_BUTTOND" but for our interface system, this makes more sense + IGNORELIST_DEL = 171, // NXT naming + IGNORELIST_ADD = 79, // NXT naming + IF_PLAYERDESIGN = 52, + CHAT_SETMODE = 244, // NXT naming + MESSAGE_PRIVATE = 148, // NXT naming + FRIENDLIST_DEL = 11, // NXT naming + FRIENDLIST_ADD = 118, // NXT naming + CLIENT_CHEAT = 4, // NXT naming + MESSAGE_PUBLIC = 158, // NXT naming + MOVE_GAMECLICK = 181, // NXT naming } \ No newline at end of file diff --git a/src/renderer.rs b/src/renderer.rs index 149836b..d15ed67 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -153,11 +153,12 @@ impl PlayerRenderer { #[inline] pub fn cache(&mut self, id: i32, message: &dyn InfoMessage, prot: PlayerInfoProt) -> usize { unsafe { + let persist: bool = prot == PlayerInfoProt::APPEARANCE; let cache: &mut Vec>> = &mut *self.caches.as_mut_ptr().add(prot.to_index()); - if (*cache.as_ptr().add(id as usize)).is_some() && !message.persists() { - return 0; - } - return PlayerRenderer::encode_info(cache, id, message); + return match *cache.as_ptr().add(id as usize) { + None => PlayerRenderer::encode_info(cache, id, message), + Some(_) => if !persist { 0 } else { PlayerRenderer::encode_info(cache, id, message) }, + }; } } @@ -343,10 +344,10 @@ impl NpcRenderer { pub fn cache(&mut self, id: i32, message: &dyn InfoMessage, prot: NpcInfoProt) -> usize { unsafe { let cache: &mut Vec>> = &mut *self.caches.as_mut_ptr().add(prot.to_index()); - if (*cache.as_ptr().add(id as usize)).is_some() && !message.persists() { - return 0; - } - return NpcRenderer::encode_info(cache, id, message); + return match *cache.as_ptr().add(id as usize) { + None => NpcRenderer::encode_info(cache, id, message), + Some(_) => 0, + }; } } From e845936662ae98d7511c7513a8b1fa1ae03db6d9 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 30 Mar 2025 10:40:00 -0400 Subject: [PATCH 02/14] chore: organize all packets individually --- src/in/anticheat.rs | 347 +++++ src/in/chat_setmode.rs | 44 + src/in/client_cheat.rs | 30 + src/in/close_modal.rs | 25 + src/in/event.rs | 77 ++ src/in/friend.rs | 58 + src/in/idle_timer.rs | 25 + src/in/if_button.rs | 30 + src/in/if_playerdesign.rs | 52 + src/in/ignore.rs | 58 + src/in/inv_button.rs | 99 ++ src/in/message_private.rs | 39 + src/in/message_public.rs | 44 + src/in/mod.rs | 25 + src/in/move_click.rs | 62 + src/in/no_timeout.rs | 25 + src/in/opheld.rs | 161 +++ src/in/oploc.rs | 161 +++ src/in/opnpc.rs | 131 ++ src/in/opobj.rs | 161 +++ src/in/opplayer.rs | 130 ++ src/in/rebuild_getmaps.rs | 34 + src/in/reportabuse.rs | 43 + src/in/resume_countdialog.rs | 30 + src/in/resume_pausebutton.rs | 29 + src/in/tutorial_clickside.rs | 30 + src/lib.rs | 36 +- src/message.rs | 1985 +-------------------------- src/out/if_openmain.rs | 38 + src/out/if_openside.rs | 38 + src/out/message_game.rs | 38 + src/out/mod.rs | 5 + src/out/npc_info.rs | 308 +++++ src/{info.rs => out/player_info.rs} | 306 +---- 34 files changed, 2414 insertions(+), 2290 deletions(-) create mode 100644 src/in/anticheat.rs create mode 100644 src/in/chat_setmode.rs create mode 100644 src/in/client_cheat.rs create mode 100644 src/in/close_modal.rs create mode 100644 src/in/event.rs create mode 100644 src/in/friend.rs create mode 100644 src/in/idle_timer.rs create mode 100644 src/in/if_button.rs create mode 100644 src/in/if_playerdesign.rs create mode 100644 src/in/ignore.rs create mode 100644 src/in/inv_button.rs create mode 100644 src/in/message_private.rs create mode 100644 src/in/message_public.rs create mode 100644 src/in/mod.rs create mode 100644 src/in/move_click.rs create mode 100644 src/in/no_timeout.rs create mode 100644 src/in/opheld.rs create mode 100644 src/in/oploc.rs create mode 100644 src/in/opnpc.rs create mode 100644 src/in/opobj.rs create mode 100644 src/in/opplayer.rs create mode 100644 src/in/rebuild_getmaps.rs create mode 100644 src/in/reportabuse.rs create mode 100644 src/in/resume_countdialog.rs create mode 100644 src/in/resume_pausebutton.rs create mode 100644 src/in/tutorial_clickside.rs create mode 100644 src/out/if_openmain.rs create mode 100644 src/out/if_openside.rs create mode 100644 src/out/message_game.rs create mode 100644 src/out/mod.rs create mode 100644 src/out/npc_info.rs rename src/{info.rs => out/player_info.rs} (57%) diff --git a/src/in/anticheat.rs b/src/in/anticheat.rs new file mode 100644 index 0000000..b4db400 --- /dev/null +++ b/src/in/anticheat.rs @@ -0,0 +1,347 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct AnticheatOp1 {} + +#[wasm_bindgen] +impl AnticheatOp1 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp1 { + return AnticheatOp1 {}; + } +} + +impl MessageDecoder for AnticheatOp1 { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp1 { + return AnticheatOp1::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp2 {} + +#[wasm_bindgen] +impl AnticheatOp2 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp2 { + return AnticheatOp2 {}; + } +} + +impl MessageDecoder for AnticheatOp2 { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp2 { + return AnticheatOp2::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp3 {} + +#[wasm_bindgen] +impl AnticheatOp3 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp3 { + return AnticheatOp3 {}; + } +} + +impl MessageDecoder for AnticheatOp3 { + fn length() -> i32 { + return 3; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp3 { + return AnticheatOp3::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp4 {} + +#[wasm_bindgen] +impl AnticheatOp4 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp4 { + return AnticheatOp4 {}; + } +} + +impl MessageDecoder for AnticheatOp4 { + fn length() -> i32 { + return 2; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp4 { + return AnticheatOp4::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp5 {} + +#[wasm_bindgen] +impl AnticheatOp5 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp5 { + return AnticheatOp5 {}; + } +} + +impl MessageDecoder for AnticheatOp5 { + fn length() -> i32 { + return 0; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp5 { + return AnticheatOp5::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp6 {} + +#[wasm_bindgen] +impl AnticheatOp6 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp6 { + return AnticheatOp6 {}; + } +} + +impl MessageDecoder for AnticheatOp6 { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp6 { + return AnticheatOp6::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp7 {} + +#[wasm_bindgen] +impl AnticheatOp7 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp7 { + return AnticheatOp7 {}; + } +} + +impl MessageDecoder for AnticheatOp7 { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp7 { + return AnticheatOp7::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp8 {} + +#[wasm_bindgen] +impl AnticheatOp8 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp8 { + return AnticheatOp8 {}; + } +} + +impl MessageDecoder for AnticheatOp8 { + fn length() -> i32 { + return 2; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp8 { + return AnticheatOp8::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatOp9 {} + +#[wasm_bindgen] +impl AnticheatOp9 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatOp9 { + return AnticheatOp9 {}; + } +} + +impl MessageDecoder for AnticheatOp9 { + fn length() -> i32 { + return 1; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp9 { + return AnticheatOp9::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle1 {} + +#[wasm_bindgen] +impl AnticheatCycle1 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle1 { + return AnticheatCycle1 {}; + } +} + +impl MessageDecoder for AnticheatCycle1 { + fn length() -> i32 { + return 1; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle1 { + return AnticheatCycle1::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle2 {} + +#[wasm_bindgen] +impl AnticheatCycle2 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle2 { + return AnticheatCycle2 {}; + } +} + +impl MessageDecoder for AnticheatCycle2 { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle2 { + return AnticheatCycle2::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle3 {} + +#[wasm_bindgen] +impl AnticheatCycle3 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle3 { + return AnticheatCycle3 {}; + } +} + +impl MessageDecoder for AnticheatCycle3 { + fn length() -> i32 { + return 3; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle3 { + return AnticheatCycle3::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle4 {} + +#[wasm_bindgen] +impl AnticheatCycle4 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle4 { + return AnticheatCycle4 {}; + } +} + +impl MessageDecoder for AnticheatCycle4 { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle4 { + return AnticheatCycle4::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle5 {} + +#[wasm_bindgen] +impl AnticheatCycle5 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle5 { + return AnticheatCycle5 {}; + } +} + +impl MessageDecoder for AnticheatCycle5 { + fn length() -> i32 { + return 0; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle5 { + return AnticheatCycle5::new(); + } +} + +// ---- + +#[wasm_bindgen] +pub struct AnticheatCycle6 {} + +#[wasm_bindgen] +impl AnticheatCycle6 { + #[wasm_bindgen(constructor)] + pub fn new() -> AnticheatCycle6 { + return AnticheatCycle6 {}; + } +} + +impl MessageDecoder for AnticheatCycle6 { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle6 { + return AnticheatCycle6::new(); + } +} \ No newline at end of file diff --git a/src/in/chat_setmode.rs b/src/in/chat_setmode.rs new file mode 100644 index 0000000..ab77adf --- /dev/null +++ b/src/in/chat_setmode.rs @@ -0,0 +1,44 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct ChatSetMode { + #[wasm_bindgen(readonly)] + pub public: u8, + #[wasm_bindgen(readonly)] + pub private: u8, + #[wasm_bindgen(readonly)] + pub trade: u8, +} + +#[wasm_bindgen] +impl ChatSetMode { + #[wasm_bindgen(constructor)] + pub fn new( + public: u8, + private: u8, + trade: u8, + ) -> ChatSetMode { + return ChatSetMode { + public, + private, + trade, + } + } +} + +impl MessageDecoder for ChatSetMode { + fn length() -> i32 { + return 3; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> ChatSetMode { + return ChatSetMode::new( + buf.g1(), + buf.g1(), + buf.g1(), + ); + } +} \ No newline at end of file diff --git a/src/in/client_cheat.rs b/src/in/client_cheat.rs new file mode 100644 index 0000000..d854a55 --- /dev/null +++ b/src/in/client_cheat.rs @@ -0,0 +1,30 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct ClientCheat { + #[wasm_bindgen(getter_with_clone, readonly)] + pub input: String, +} + +#[wasm_bindgen] +impl ClientCheat { + #[wasm_bindgen(constructor)] + pub fn new(input: String) -> ClientCheat { + return ClientCheat { + input, + } + } +} + +impl MessageDecoder for ClientCheat { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> ClientCheat { + return ClientCheat::new(buf.gjstr(10)); + } +} \ No newline at end of file diff --git a/src/in/close_modal.rs b/src/in/close_modal.rs new file mode 100644 index 0000000..b53942b --- /dev/null +++ b/src/in/close_modal.rs @@ -0,0 +1,25 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct CloseModal {} + +#[wasm_bindgen] +impl CloseModal { + #[wasm_bindgen(constructor)] + pub fn new() -> CloseModal { + return CloseModal {} + } +} + +impl MessageDecoder for CloseModal { + fn length() -> i32 { + return 0; + } + + fn decode(_: ClientProt, _: &mut Packet) -> CloseModal { + return CloseModal::new(); + } +} \ No newline at end of file diff --git a/src/in/event.rs b/src/in/event.rs new file mode 100644 index 0000000..5860f3c --- /dev/null +++ b/src/in/event.rs @@ -0,0 +1,77 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct EventTracking { + #[wasm_bindgen(getter_with_clone, readonly)] + pub bytes: Vec, +} + +#[wasm_bindgen] +impl EventTracking { + #[wasm_bindgen(constructor)] + pub fn new(bytes: Vec) -> EventTracking { + return EventTracking { + bytes, + } + } +} + +impl MessageDecoder for EventTracking { + fn length() -> i32 { + return -2; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> EventTracking { + return EventTracking::new(buf.data.clone()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct EventCameraPosition { + #[wasm_bindgen(readonly)] + pub pitch: i32, + #[wasm_bindgen(readonly)] + pub yaw: i32, + #[wasm_bindgen(readonly)] + pub angle: i32, + #[wasm_bindgen(readonly)] + pub zoom: i32, +} + +#[wasm_bindgen] +impl EventCameraPosition { + #[wasm_bindgen(constructor)] + pub fn new( + pitch: i32, + yaw: i32, + angle: i32, + zoom: i32, + ) -> EventCameraPosition { + return EventCameraPosition { + pitch, + yaw, + angle, + zoom, + } + } +} + +impl MessageDecoder for EventCameraPosition { + fn length() -> i32 { + return 6; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> EventCameraPosition { + return EventCameraPosition::new( + buf.g2() as i32, + buf.g2() as i32, + buf.g1() as i32, + buf.g1() as i32, + ); + } +} \ No newline at end of file diff --git a/src/in/friend.rs b/src/in/friend.rs new file mode 100644 index 0000000..3b2f994 --- /dev/null +++ b/src/in/friend.rs @@ -0,0 +1,58 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct FriendListAdd { + #[wasm_bindgen(readonly)] + pub username: i64, +} + +#[wasm_bindgen] +impl FriendListAdd { + #[wasm_bindgen(constructor)] + pub fn new(username: i64) -> FriendListAdd { + return FriendListAdd { + username, + } + } +} + +impl MessageDecoder for FriendListAdd { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> FriendListAdd { + return FriendListAdd::new(buf.g8s()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct FriendListDel { + #[wasm_bindgen(readonly)] + pub username: i64, +} + +#[wasm_bindgen] +impl FriendListDel { + #[wasm_bindgen(constructor)] + pub fn new(username: i64) -> FriendListDel { + return FriendListDel { + username, + } + } +} + +impl MessageDecoder for FriendListDel { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> FriendListDel { + return FriendListDel::new(buf.g8s()); + } +} \ No newline at end of file diff --git a/src/in/idle_timer.rs b/src/in/idle_timer.rs new file mode 100644 index 0000000..93ab5c4 --- /dev/null +++ b/src/in/idle_timer.rs @@ -0,0 +1,25 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct IdleTimer {} + +#[wasm_bindgen] +impl IdleTimer { + #[wasm_bindgen(constructor)] + pub fn new() -> IdleTimer { + return IdleTimer {} + } +} + +impl MessageDecoder for IdleTimer { + fn length() -> i32 { + return 0; + } + + fn decode(_: ClientProt, _: &mut Packet) -> IdleTimer { + return IdleTimer::new(); + } +} \ No newline at end of file diff --git a/src/in/if_button.rs b/src/in/if_button.rs new file mode 100644 index 0000000..58c6192 --- /dev/null +++ b/src/in/if_button.rs @@ -0,0 +1,30 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct IfButton { + #[wasm_bindgen(readonly)] + pub component: u16, +} + +#[wasm_bindgen] +impl IfButton { + #[wasm_bindgen(constructor)] + pub fn new(component: u16) -> IfButton { + return IfButton { + component, + } + } +} + +impl MessageDecoder for IfButton { + fn length() -> i32 { + return 2; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> IfButton { + return IfButton::new(buf.g2()); + } +} \ No newline at end of file diff --git a/src/in/if_playerdesign.rs b/src/in/if_playerdesign.rs new file mode 100644 index 0000000..1aa1b4a --- /dev/null +++ b/src/in/if_playerdesign.rs @@ -0,0 +1,52 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct IfPlayerDesign { + #[wasm_bindgen(readonly)] + pub gender: u8, + #[wasm_bindgen(getter_with_clone, readonly)] + pub idkit: Vec, + #[wasm_bindgen(getter_with_clone, readonly)] + pub color: Vec, +} + +#[wasm_bindgen] +impl IfPlayerDesign { + #[wasm_bindgen(constructor)] + pub fn new(gender: u8, idkit: Vec, color: Vec) -> IfPlayerDesign { + return IfPlayerDesign { + gender, + idkit, + color, + } + } +} + +impl MessageDecoder for IfPlayerDesign { + fn length() -> i32 { + return 13; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> IfPlayerDesign { + let gender: u8 = buf.g1(); + + let mut idkit: [i32; 7] = [0; 7]; + for i in 0..7 { + let mut v = buf.g1() as i32; + if v == 0xff { + v = -1; + } + unsafe { *idkit.as_mut_ptr().add(i as usize) = v }; + } + + let mut color: [i32; 5] = [0; 5]; + for i in 0..5 { + unsafe { *color.as_mut_ptr().add(i as usize) = buf.g1() as i32 }; + } + + return IfPlayerDesign::new(gender, idkit.to_vec(), color.to_vec()); + } +} \ No newline at end of file diff --git a/src/in/ignore.rs b/src/in/ignore.rs new file mode 100644 index 0000000..d89c804 --- /dev/null +++ b/src/in/ignore.rs @@ -0,0 +1,58 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct IgnoreListAdd { + #[wasm_bindgen(readonly)] + pub username: i64, +} + +#[wasm_bindgen] +impl IgnoreListAdd { + #[wasm_bindgen(constructor)] + pub fn new(username: i64) -> IgnoreListAdd { + return IgnoreListAdd { + username, + } + } +} + +impl MessageDecoder for IgnoreListAdd { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> IgnoreListAdd { + return IgnoreListAdd::new(buf.g8s()); + } +} + +// ---- + +#[wasm_bindgen] +pub struct IgnoreListDel { + #[wasm_bindgen(readonly)] + pub username: i64, +} + +#[wasm_bindgen] +impl IgnoreListDel { + #[wasm_bindgen(constructor)] + pub fn new(username: i64) -> IgnoreListDel { + return IgnoreListDel { + username, + } + } +} + +impl MessageDecoder for IgnoreListDel { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> IgnoreListDel { + return IgnoreListDel::new(buf.g8s()); + } +} \ No newline at end of file diff --git a/src/in/inv_button.rs b/src/in/inv_button.rs new file mode 100644 index 0000000..667ab4c --- /dev/null +++ b/src/in/inv_button.rs @@ -0,0 +1,99 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct InvButton { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly)] + pub slot: u16, + #[wasm_bindgen(readonly)] + pub component: u16, +} + +#[wasm_bindgen] +impl InvButton { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + obj: u16, + slot: u16, + component: u16, + ) -> InvButton { + return InvButton { + op, + obj, + slot, + component, + } + } +} + +impl MessageDecoder for InvButton { + fn length() -> i32 { + return 6; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> InvButton { + let op: u8 = match prot { + ClientProt::INV_BUTTON1 => 1, + ClientProt::INV_BUTTON2 => 2, + ClientProt::INV_BUTTON3 => 3, + ClientProt::INV_BUTTON4 => 4, + ClientProt::INV_BUTTON5 => 5, + _ => 0, + }; + return InvButton::new( + op, + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct InvButtonD { + #[wasm_bindgen(readonly)] + pub component: u16, + #[wasm_bindgen(readonly)] + pub slot: u16, + #[wasm_bindgen(readonly)] + pub target: u16, +} + +#[wasm_bindgen] +impl InvButtonD { + #[wasm_bindgen(constructor)] + pub fn new( + component: u16, + slot: u16, + target: u16, + ) -> InvButtonD { + return InvButtonD { + component, + slot, + target, + } + } +} + +impl MessageDecoder for InvButtonD { + fn length() -> i32 { + return 6; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> InvButtonD { + return InvButtonD::new( + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} \ No newline at end of file diff --git a/src/in/message_private.rs b/src/in/message_private.rs new file mode 100644 index 0000000..feebcb6 --- /dev/null +++ b/src/in/message_private.rs @@ -0,0 +1,39 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct MessagePrivate { + #[wasm_bindgen(readonly)] + pub username: i64, + #[wasm_bindgen(getter_with_clone, readonly)] + pub input: Vec, +} + +#[wasm_bindgen] +impl MessagePrivate { + #[wasm_bindgen(constructor)] + pub fn new( + username: i64, + input: Vec, + ) -> MessagePrivate { + return MessagePrivate { + username, + input, + } + } +} + +impl MessageDecoder for MessagePrivate { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> MessagePrivate { + return MessagePrivate::new( + buf.g8s(), + unsafe { buf.data.get_unchecked(buf.pos..buf.pos + buf.data.len() - 8).to_vec() } + ); + } +} \ No newline at end of file diff --git a/src/in/message_public.rs b/src/in/message_public.rs new file mode 100644 index 0000000..819b6fd --- /dev/null +++ b/src/in/message_public.rs @@ -0,0 +1,44 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct MessagePublic { + #[wasm_bindgen(readonly)] + pub color: u8, + #[wasm_bindgen(readonly)] + pub effect: u8, + #[wasm_bindgen(getter_with_clone, readonly)] + pub input: Vec, +} + +#[wasm_bindgen] +impl MessagePublic { + #[wasm_bindgen(constructor)] + pub fn new( + color: u8, + effect: u8, + input: Vec, + ) -> MessagePublic { + return MessagePublic { + color, + effect, + input, + } + } +} + +impl MessageDecoder for MessagePublic { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> MessagePublic { + return MessagePublic::new( + buf.g1(), + buf.g1(), + unsafe { buf.data.get_unchecked(buf.pos..buf.pos + buf.data.len() - 2).to_vec() } + ); + } +} \ No newline at end of file diff --git a/src/in/mod.rs b/src/in/mod.rs new file mode 100644 index 0000000..6ae4a5d --- /dev/null +++ b/src/in/mod.rs @@ -0,0 +1,25 @@ +pub mod client_cheat; +pub mod close_modal; +pub mod friend; +pub mod idle_timer; +pub mod if_button; +pub mod if_playerdesign; +pub mod ignore; +pub mod inv_button; +pub mod message_private; +pub mod message_public; +pub mod move_click; +pub mod no_timeout; +pub mod opheld; +pub mod oploc; +pub mod opnpc; +pub mod opobj; +pub mod opplayer; +pub mod rebuild_getmaps; +pub mod resume_pausebutton; +pub mod resume_countdialog; +pub mod tutorial_clickside; +pub mod chat_setmode; +pub mod reportabuse; +pub mod event; +pub mod anticheat; \ No newline at end of file diff --git a/src/in/move_click.rs b/src/in/move_click.rs new file mode 100644 index 0000000..02e6773 --- /dev/null +++ b/src/in/move_click.rs @@ -0,0 +1,62 @@ +use crate::coord::CoordGrid; +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct MoveClick { + #[wasm_bindgen(readonly)] + pub ctrl: bool, + #[wasm_bindgen(readonly)] + pub op: bool, + #[wasm_bindgen(getter_with_clone, readonly)] + pub path: Vec, +} + +#[wasm_bindgen] +impl MoveClick { + #[wasm_bindgen(constructor)] + pub fn new( + ctrl: bool, + op: bool, + path: Vec, + ) -> MoveClick { + return MoveClick { + ctrl, + op, + path, + } + } +} + +impl MessageDecoder for MoveClick { + fn length() -> i32 { + return -1; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> MoveClick { + let ctrl: bool = buf.g1() == 1; + let x: u16 = buf.g2(); + let z: u16 = buf.g2(); + + let offset: usize = if prot == ClientProt::MOVE_MINIMAPCLICK { 14 } else { 0 }; + let waypoints: usize = ((buf.data.len() - buf.pos - offset) / 2) + 1; + + let mut path: Vec = vec![0; waypoints]; + path[0] = CoordGrid::from(x, 0, z).packed; + + for index in 1..waypoints { + if index >= 25 { + break; + } + unsafe { *path.as_mut_ptr().add(index) = CoordGrid::from(x + buf.g1s() as u16, 0, z + buf.g1s() as u16).packed }; + } + + return MoveClick::new( + ctrl, + prot == ClientProt::MOVE_OPCLICK, + path, + ); + } +} \ No newline at end of file diff --git a/src/in/no_timeout.rs b/src/in/no_timeout.rs new file mode 100644 index 0000000..43b5557 --- /dev/null +++ b/src/in/no_timeout.rs @@ -0,0 +1,25 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct NoTimeout {} + +#[wasm_bindgen] +impl NoTimeout { + #[wasm_bindgen(constructor)] + pub fn new() -> NoTimeout { + return NoTimeout {}; + } +} + +impl MessageDecoder for NoTimeout { + fn length() -> i32 { + return 0; + } + + fn decode(_: ClientProt, _: &mut Packet) -> NoTimeout { + return NoTimeout::new(); + } +} \ No newline at end of file diff --git a/src/in/opheld.rs b/src/in/opheld.rs new file mode 100644 index 0000000..7ba02cc --- /dev/null +++ b/src/in/opheld.rs @@ -0,0 +1,161 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct OpHeld { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly)] + pub slot: u16, + #[wasm_bindgen(readonly)] + pub component: u16, +} + +#[wasm_bindgen] +impl OpHeld { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + obj: u16, + slot: u16, + component: u16, + ) -> OpHeld { + return OpHeld { + op, + obj, + slot, + component, + } + } +} + +impl MessageDecoder for OpHeld { + fn length() -> i32 { + return 6; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> OpHeld { + let op: u8 = match prot { + ClientProt::OPHELD1 => 1, + ClientProt::OPHELD2 => 2, + ClientProt::OPHELD3 => 3, + ClientProt::OPHELD4 => 4, + ClientProt::OPHELD5 => 5, + _ => 0, + }; + return OpHeld::new( + op, + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpHeldT { + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly)] + pub slot: u16, + #[wasm_bindgen(readonly)] + pub component: u16, + #[wasm_bindgen(readonly)] + pub spell: u16, +} + +#[wasm_bindgen] +impl OpHeldT { + #[wasm_bindgen(constructor)] + pub fn new( + obj: u16, + slot: u16, + component: u16, + spell: u16, + ) -> OpHeldT { + return OpHeldT { + obj, + slot, + component, + spell, + } + } +} + +impl MessageDecoder for OpHeldT { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpHeldT { + return OpHeldT::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpHeldU { + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly)] + pub slot: u16, + #[wasm_bindgen(readonly)] + pub component: u16, + #[wasm_bindgen(readonly, js_name = useObj)] + pub use_obj: u16, + #[wasm_bindgen(readonly, js_name = useSlot)] + pub use_slot: u16, + #[wasm_bindgen(readonly, js_name = useComponent)] + pub use_component: u16, +} + +#[wasm_bindgen] +impl OpHeldU { + #[wasm_bindgen(constructor)] + pub fn new( + obj: u16, + slot: u16, + component: u16, + use_obj: u16, + use_slot: u16, + use_component: u16, + ) -> OpHeldU { + return OpHeldU { + obj, + slot, + component, + use_obj, + use_slot, + use_component, + } + } +} + +impl MessageDecoder for OpHeldU { + fn length() -> i32 { + return 12; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpHeldU { + return OpHeldU::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} \ No newline at end of file diff --git a/src/in/oploc.rs b/src/in/oploc.rs new file mode 100644 index 0000000..fe97dc5 --- /dev/null +++ b/src/in/oploc.rs @@ -0,0 +1,161 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct OpLoc { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub loc: u16, +} + +#[wasm_bindgen] +impl OpLoc { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + x: u16, + z: u16, + loc: u16, + ) -> OpLoc { + return OpLoc { + op, + x, + z, + loc, + } + } +} + +impl MessageDecoder for OpLoc { + fn length() -> i32 { + return 6; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> OpLoc { + let op: u8 = match prot { + ClientProt::OPLOC1 => 1, + ClientProt::OPLOC2 => 2, + ClientProt::OPLOC3 => 3, + ClientProt::OPLOC4 => 4, + ClientProt::OPLOC5 => 5, + _ => 0, + }; + return OpLoc::new( + op, + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpLocT { + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub loc: u16, + #[wasm_bindgen(readonly)] + pub spell: u16, +} + +#[wasm_bindgen] +impl OpLocT { + #[wasm_bindgen(constructor)] + pub fn new( + x: u16, + z: u16, + loc: u16, + spell: u16, + ) -> OpLocT { + return OpLocT { + x, + z, + loc, + spell, + } + } +} + +impl MessageDecoder for OpLocT { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpLocT { + return OpLocT::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpLocU { + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub loc: u16, + #[wasm_bindgen(readonly, js_name = useObj)] + pub use_obj: u16, + #[wasm_bindgen(readonly, js_name = useSlot)] + pub use_slot: u16, + #[wasm_bindgen(readonly, js_name = useComponent)] + pub use_component: u16, +} + +#[wasm_bindgen] +impl OpLocU { + #[wasm_bindgen(constructor)] + pub fn new( + x: u16, + z: u16, + loc: u16, + use_obj: u16, + use_slot: u16, + use_component: u16, + ) -> OpLocU { + return OpLocU { + x, + z, + loc, + use_obj, + use_slot, + use_component, + } + } +} + +impl MessageDecoder for OpLocU { + fn length() -> i32 { + return 12; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpLocU { + return OpLocU::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} \ No newline at end of file diff --git a/src/in/opnpc.rs b/src/in/opnpc.rs new file mode 100644 index 0000000..65c6e37 --- /dev/null +++ b/src/in/opnpc.rs @@ -0,0 +1,131 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct OpNpc { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub nid: u16, +} + +#[wasm_bindgen] +impl OpNpc { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + nid: u16, + ) -> OpNpc { + return OpNpc { + op, + nid, + } + } +} + +impl MessageDecoder for OpNpc { + fn length() -> i32 { + return 2; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> OpNpc { + let op: u8 = match prot { + ClientProt::OPNPC1 => 1, + ClientProt::OPNPC2 => 2, + ClientProt::OPNPC3 => 3, + ClientProt::OPNPC4 => 4, + ClientProt::OPNPC5 => 5, + _ => 0, + }; + return OpNpc::new( + op, + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpNpcT { + #[wasm_bindgen(readonly)] + pub nid: u16, + #[wasm_bindgen(readonly)] + pub spell: u16, +} + +#[wasm_bindgen] +impl OpNpcT { + #[wasm_bindgen(constructor)] + pub fn new( + nid: u16, + spell: u16, + ) -> OpNpcT { + return OpNpcT { + nid, + spell, + } + } +} + +impl MessageDecoder for OpNpcT { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpNpcT { + return OpNpcT::new( + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpNpcU { + #[wasm_bindgen(readonly)] + pub nid: u16, + #[wasm_bindgen(readonly, js_name = useObj)] + pub use_obj: u16, + #[wasm_bindgen(readonly, js_name = useSlot)] + pub use_slot: u16, + #[wasm_bindgen(readonly, js_name = useComponent)] + pub use_component: u16, +} + +#[wasm_bindgen] +impl OpNpcU { + #[wasm_bindgen(constructor)] + pub fn new( + nid: u16, + use_obj: u16, + use_slot: u16, + use_component: u16, + ) -> OpNpcU { + return OpNpcU { + nid, + use_obj, + use_slot, + use_component, + } + } +} + +impl MessageDecoder for OpNpcU { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpNpcU { + return OpNpcU::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} \ No newline at end of file diff --git a/src/in/opobj.rs b/src/in/opobj.rs new file mode 100644 index 0000000..f0f47ff --- /dev/null +++ b/src/in/opobj.rs @@ -0,0 +1,161 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct OpObj { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub obj: u16, +} + +#[wasm_bindgen] +impl OpObj { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + x: u16, + z: u16, + obj: u16, + ) -> OpObj { + return OpObj { + op, + x, + z, + obj, + } + } +} + +impl MessageDecoder for OpObj { + fn length() -> i32 { + return 6; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> OpObj { + let op: u8 = match prot { + ClientProt::OPOBJ1 => 1, + ClientProt::OPOBJ2 => 2, + ClientProt::OPOBJ3 => 3, + ClientProt::OPOBJ4 => 4, + ClientProt::OPOBJ5 => 5, + _ => 0, + }; + return OpObj::new( + op, + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpObjT { + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly)] + pub spell: u16, +} + +#[wasm_bindgen] +impl OpObjT { + #[wasm_bindgen(constructor)] + pub fn new( + x: u16, + z: u16, + obj: u16, + spell: u16, + ) -> OpObjT { + return OpObjT { + x, + z, + obj, + spell, + } + } +} + +impl MessageDecoder for OpObjT { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpObjT { + return OpObjT::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpObjU { + #[wasm_bindgen(readonly)] + pub x: u16, + #[wasm_bindgen(readonly)] + pub z: u16, + #[wasm_bindgen(readonly)] + pub obj: u16, + #[wasm_bindgen(readonly, js_name = useObj)] + pub use_obj: u16, + #[wasm_bindgen(readonly, js_name = useSlot)] + pub use_slot: u16, + #[wasm_bindgen(readonly, js_name = useComponent)] + pub use_component: u16, +} + +#[wasm_bindgen] +impl OpObjU { + #[wasm_bindgen(constructor)] + pub fn new( + x: u16, + z: u16, + obj: u16, + use_obj: u16, + use_slot: u16, + use_component: u16, + ) -> OpObjU { + return OpObjU { + x, + z, + obj, + use_obj, + use_slot, + use_component, + } + } +} + +impl MessageDecoder for OpObjU { + fn length() -> i32 { + return 12; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpObjU { + return OpObjU::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} \ No newline at end of file diff --git a/src/in/opplayer.rs b/src/in/opplayer.rs new file mode 100644 index 0000000..09c7532 --- /dev/null +++ b/src/in/opplayer.rs @@ -0,0 +1,130 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct OpPlayer { + #[wasm_bindgen(readonly)] + pub op: u8, + #[wasm_bindgen(readonly)] + pub pid: u16, +} + +#[wasm_bindgen] +impl OpPlayer { + #[wasm_bindgen(constructor)] + pub fn new( + op: u8, + pid: u16, + ) -> OpPlayer { + return OpPlayer { + op, + pid, + } + } +} + +impl MessageDecoder for OpPlayer { + fn length() -> i32 { + return 2; + } + + fn decode(prot: ClientProt, buf: &mut Packet) -> OpPlayer { + let op: u8 = match prot { + ClientProt::OPPLAYER1 => 1, + ClientProt::OPPLAYER2 => 2, + ClientProt::OPPLAYER3 => 3, + ClientProt::OPPLAYER4 => 4, + _ => 0, + }; + return OpPlayer::new( + op, + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpPlayerT { + #[wasm_bindgen(readonly)] + pub pid: u16, + #[wasm_bindgen(readonly)] + pub spell: u16, +} + +#[wasm_bindgen] +impl OpPlayerT { + #[wasm_bindgen(constructor)] + pub fn new( + pid: u16, + spell: u16, + ) -> OpPlayerT { + return OpPlayerT { + pid, + spell, + } + } +} + +impl MessageDecoder for OpPlayerT { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpPlayerT { + return OpPlayerT::new( + buf.g2(), + buf.g2(), + ); + } +} + +// ---- + +#[wasm_bindgen] +pub struct OpPlayerU { + #[wasm_bindgen(readonly)] + pub pid: u16, + #[wasm_bindgen(readonly, js_name = useObj)] + pub use_obj: u16, + #[wasm_bindgen(readonly, js_name = useSlot)] + pub use_slot: u16, + #[wasm_bindgen(readonly, js_name = useComponent)] + pub use_component: u16, +} + +#[wasm_bindgen] +impl OpPlayerU { + #[wasm_bindgen(constructor)] + pub fn new( + pid: u16, + use_obj: u16, + use_slot: u16, + use_component: u16, + ) -> OpPlayerU { + return OpPlayerU { + pid, + use_obj, + use_slot, + use_component, + } + } +} + +impl MessageDecoder for OpPlayerU { + fn length() -> i32 { + return 8; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> OpPlayerU { + return OpPlayerU::new( + buf.g2(), + buf.g2(), + buf.g2(), + buf.g2(), + ); + } +} \ No newline at end of file diff --git a/src/in/rebuild_getmaps.rs b/src/in/rebuild_getmaps.rs new file mode 100644 index 0000000..d0ab2c4 --- /dev/null +++ b/src/in/rebuild_getmaps.rs @@ -0,0 +1,34 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct RebuildGetMaps { + #[wasm_bindgen(getter_with_clone, readonly)] + pub maps: Vec, +} + +#[wasm_bindgen] +impl RebuildGetMaps { + #[wasm_bindgen(constructor)] + pub fn new(maps: Vec) -> RebuildGetMaps { + return RebuildGetMaps { + maps, + } + } +} + +impl MessageDecoder for RebuildGetMaps { + fn length() -> i32 { + return -1; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> RebuildGetMaps { + let mut maps: Vec = vec![0; buf.data.len() / 3]; + for index in 0..maps.len() { + unsafe { *maps.as_mut_ptr().add(index) = buf.g3() as u32 }; + } + return RebuildGetMaps::new(maps); + } +} \ No newline at end of file diff --git a/src/in/reportabuse.rs b/src/in/reportabuse.rs new file mode 100644 index 0000000..0ccb5fe --- /dev/null +++ b/src/in/reportabuse.rs @@ -0,0 +1,43 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct ReportAbuse { + #[wasm_bindgen(readonly)] + pub offender: i64, + #[wasm_bindgen(readonly)] + pub reason: u8, + #[wasm_bindgen(readonly)] + pub mute: bool, +} + +#[wasm_bindgen] +impl ReportAbuse { + pub fn new( + offender: i64, + reason: u8, + mute: bool, + ) -> ReportAbuse { + return ReportAbuse { + offender, + reason, + mute, + } + } +} + +impl MessageDecoder for ReportAbuse { + fn length() -> i32 { + return 10; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> ReportAbuse { + return ReportAbuse::new( + buf.g8s(), + buf.g1(), + buf.g1() == 1, + ); + } +} \ No newline at end of file diff --git a/src/in/resume_countdialog.rs b/src/in/resume_countdialog.rs new file mode 100644 index 0000000..a426ce5 --- /dev/null +++ b/src/in/resume_countdialog.rs @@ -0,0 +1,30 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct ResumePCountDialog { + #[wasm_bindgen(readonly)] + pub input: i32, +} + +#[wasm_bindgen] +impl ResumePCountDialog { + #[wasm_bindgen(constructor)] + pub fn new(input: i32) -> ResumePCountDialog { + return ResumePCountDialog { + input, + } + } +} + +impl MessageDecoder for ResumePCountDialog { + fn length() -> i32 { + return 4; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> ResumePCountDialog { + return ResumePCountDialog::new(buf.g4s()); + } +} \ No newline at end of file diff --git a/src/in/resume_pausebutton.rs b/src/in/resume_pausebutton.rs new file mode 100644 index 0000000..d4e8974 --- /dev/null +++ b/src/in/resume_pausebutton.rs @@ -0,0 +1,29 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct ResumePauseButton { + #[wasm_bindgen(readonly)] + pub component: u16, +} + +#[wasm_bindgen] +impl ResumePauseButton { + pub fn new(component: u16) -> ResumePauseButton { + return ResumePauseButton { + component, + }; + } +} + +impl MessageDecoder for ResumePauseButton { + fn length() -> i32 { + return 2; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> ResumePauseButton { + return ResumePauseButton::new(buf.g2()); + } +} \ No newline at end of file diff --git a/src/in/tutorial_clickside.rs b/src/in/tutorial_clickside.rs new file mode 100644 index 0000000..bd7e667 --- /dev/null +++ b/src/in/tutorial_clickside.rs @@ -0,0 +1,30 @@ +use crate::message::MessageDecoder; +use crate::packet::Packet; +use crate::prot::ClientProt; +use wasm_bindgen::prelude::wasm_bindgen; + +#[wasm_bindgen] +pub struct TutorialClickSide { + #[wasm_bindgen(readonly)] + pub tab: u8, +} + +#[wasm_bindgen] +impl TutorialClickSide { + #[wasm_bindgen(constructor)] + pub fn new(tab: u8) -> TutorialClickSide { + return TutorialClickSide { + tab, + } + } +} + +impl MessageDecoder for TutorialClickSide { + fn length() -> i32 { + return 1; + } + + fn decode(_: ClientProt, buf: &mut Packet) -> TutorialClickSide { + return TutorialClickSide::new(buf.g1()); + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 2a6519c..8791965 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,15 +2,44 @@ use crate::coord::CoordGrid; use crate::grid::ZoneMap; -use crate::info::{NpcInfo, PlayerInfo}; -use crate::message::{AnticheatCycle1, AnticheatCycle2, AnticheatCycle3, AnticheatCycle4, AnticheatCycle5, AnticheatCycle6, AnticheatOp1, AnticheatOp2, AnticheatOp3, AnticheatOp4, AnticheatOp5, AnticheatOp6, AnticheatOp7, AnticheatOp8, AnticheatOp9, ChatSetMode, ClientCheat, CloseModal, EventCameraPosition, EventTracking, FriendListAdd, FriendListDel, IdleTimer, IfButton, IfOpenMain, IfOpenSide, IfPlayerDesign, IgnoreListAdd, IgnoreListDel, IncomingPacket, InfoMessage, InvButton, InvButtonD, MessageDecoder, MessageEncoder, MessageGame, MessagePrivate, MessagePublic, MoveClick, NoTimeout, OpHeld, OpHeldT, OpHeldU, OpLoc, OpLocT, OpLocU, OpNpc, OpNpcT, OpNpcU, OpObj, OpObjT, OpObjU, OpPlayer, OpPlayerT, OpPlayerU, OutgoingPacket, RebuildGetMaps, ReportAbuse, ResumePCountDialog, ResumePauseButton, TutorialClickSide}; +use crate::message::{IncomingPacket, MessageDecoder, OutgoingPacket}; use crate::npc::Npc; +use crate::out::if_openmain::IfOpenMain; +use crate::out::if_openside::IfOpenSide; +use crate::out::message_game::MessageGame; +use crate::out::npc_info::NpcInfo; use crate::packet::Packet; use crate::player::{Chat, ExactMove, Player}; use crate::prot::{ClientInternalProt, ClientProt}; +use crate::r#in::anticheat::{AnticheatCycle1, AnticheatCycle2, AnticheatCycle3, AnticheatCycle4, AnticheatCycle5, AnticheatCycle6, AnticheatOp1, AnticheatOp2, AnticheatOp3, AnticheatOp4, AnticheatOp5, AnticheatOp6, AnticheatOp7, AnticheatOp8, AnticheatOp9}; +use crate::r#in::chat_setmode::ChatSetMode; +use crate::r#in::client_cheat::ClientCheat; +use crate::r#in::close_modal::CloseModal; +use crate::r#in::event::{EventCameraPosition, EventTracking}; +use crate::r#in::friend::{FriendListAdd, FriendListDel}; +use crate::r#in::idle_timer::IdleTimer; +use crate::r#in::if_button::IfButton; +use crate::r#in::if_playerdesign::IfPlayerDesign; +use crate::r#in::ignore::{IgnoreListAdd, IgnoreListDel}; +use crate::r#in::inv_button::{InvButton, InvButtonD}; +use crate::r#in::message_private::MessagePrivate; +use crate::r#in::message_public::MessagePublic; +use crate::r#in::move_click::MoveClick; +use crate::r#in::no_timeout::NoTimeout; +use crate::r#in::opheld::{OpHeld, OpHeldT, OpHeldU}; +use crate::r#in::oploc::{OpLoc, OpLocT, OpLocU}; +use crate::r#in::opnpc::{OpNpc, OpNpcT, OpNpcU}; +use crate::r#in::opobj::{OpObj, OpObjT, OpObjU}; +use crate::r#in::opplayer::{OpPlayer, OpPlayerT, OpPlayerU}; +use crate::r#in::rebuild_getmaps::RebuildGetMaps; +use crate::r#in::reportabuse::ReportAbuse; +use crate::r#in::resume_countdialog::ResumePCountDialog; +use crate::r#in::resume_pausebutton::ResumePauseButton; +use crate::r#in::tutorial_clickside::TutorialClickSide; use crate::renderer::{NpcRenderer, PlayerRenderer}; use crate::visibility::Visibility; use once_cell::sync::Lazy; +use out::player_info::PlayerInfo; use std::collections::HashMap; use std::ptr::{addr_of, addr_of_mut}; use wasm_bindgen::prelude::wasm_bindgen; @@ -23,12 +52,13 @@ mod coord; mod player; mod prot; mod message; -mod info; mod grid; mod npc; mod visibility; mod priority; mod category; +mod r#in; +mod out; static mut PLAYERS: Lazy>> = Lazy::new(|| vec![None; 2048]); static mut PLAYER_GRID: Lazy>> = Lazy::new(|| HashMap::with_capacity(2048)); diff --git a/src/message.rs b/src/message.rs index 30b53a3..0404a83 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,8 +1,7 @@ use crate::packet::Packet; use crate::priority::ServerProtPriority; -use crate::prot::{ClientProt, ServerInternalProt}; +use crate::prot::ClientProt; use wasm_bindgen::prelude::wasm_bindgen; -use crate::coord::CoordGrid; pub trait InfoMessage { fn encode(&self, buf: &mut Packet); @@ -608,1985 +607,3 @@ impl InfoMessage for NpcInfoSpotanim { return 6; } } - -// ---- encoders - -pub struct IfOpenMain { - component: i32, -} - -impl IfOpenMain { - pub fn new(component:i32) -> IfOpenMain { - return IfOpenMain { - component, - } - } -} - -impl MessageEncoder for IfOpenMain { - fn id(&self) -> i32 { - return ServerInternalProt::IF_OPENMAIN as i32; - } - - fn length(&self) -> i32 { - return 2; - } - - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - - fn encode(&self, buf: &mut Packet) { - buf.p2(self.component); - } - - fn test(&self) -> usize { - return 2; - } -} - -// ---- - -pub struct IfOpenSide { - component: i32, -} - -impl IfOpenSide { - pub fn new(component:i32) -> IfOpenSide { - return IfOpenSide { - component, - } - } -} - -impl MessageEncoder for IfOpenSide { - fn id(&self) -> i32 { - return ServerInternalProt::IF_OPENSIDE as i32 - } - - fn length(&self) -> i32 { - return 2; - } - - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - - fn encode(&self, buf: &mut Packet) { - buf.p2(self.component); - } - - fn test(&self) -> usize { - return 2; - } -} - -// ---- - -pub struct MessageGame { - msg: String, -} - -impl MessageGame { - pub fn new(msg: String) -> MessageGame { - return MessageGame { - msg, - } - } -} - -impl MessageEncoder for MessageGame { - fn id(&self) -> i32 { - return ServerInternalProt::MESSAGE_GAME as i32 - } - - fn length(&self) -> i32 { - return -1; - } - - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - - fn encode(&self, buf: &mut Packet) { - buf.pjstr(&self.msg, 10); - } - - fn test(&self) -> usize { - return 1 + self.msg.len(); - } -} - -// ---- decoders - -#[wasm_bindgen] -pub struct ClientCheat { - #[wasm_bindgen(getter_with_clone, readonly)] - pub input: String, -} - -#[wasm_bindgen] -impl ClientCheat { - #[wasm_bindgen(constructor)] - pub fn new(input: String) -> ClientCheat { - return ClientCheat { - input, - } - } -} - -impl MessageDecoder for ClientCheat { - fn length() -> i32 { - return -1; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> ClientCheat { - return ClientCheat::new(buf.gjstr(10)); - } -} - -// ---- - -#[wasm_bindgen] -pub struct CloseModal {} - -#[wasm_bindgen] -impl CloseModal { - #[wasm_bindgen(constructor)] - pub fn new() -> CloseModal { - return CloseModal {} - } -} - -impl MessageDecoder for CloseModal { - fn length() -> i32 { - return 0; - } - - fn decode(_: ClientProt, _: &mut Packet) -> CloseModal { - return CloseModal::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct FriendListAdd { - #[wasm_bindgen(readonly)] - pub username: i64, -} - -#[wasm_bindgen] -impl FriendListAdd { - #[wasm_bindgen(constructor)] - pub fn new(username: i64) -> FriendListAdd { - return FriendListAdd { - username, - } - } -} - -impl MessageDecoder for FriendListAdd { - fn length() -> i32 { - return 8; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> FriendListAdd { - return FriendListAdd::new(buf.g8s()); - } -} - -// ---- - -#[wasm_bindgen] -pub struct FriendListDel { - #[wasm_bindgen(readonly)] - pub username: i64, -} - -#[wasm_bindgen] -impl FriendListDel { - #[wasm_bindgen(constructor)] - pub fn new(username: i64) -> FriendListDel { - return FriendListDel { - username, - } - } -} - -impl MessageDecoder for FriendListDel { - fn length() -> i32 { - return 8; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> FriendListDel { - return FriendListDel::new(buf.g8s()); - } -} - -// ---- - -#[wasm_bindgen] -pub struct IdleTimer {} - -#[wasm_bindgen] -impl IdleTimer { - #[wasm_bindgen(constructor)] - pub fn new() -> IdleTimer { - return IdleTimer {} - } -} - -impl MessageDecoder for IdleTimer { - fn length() -> i32 { - return 0; - } - - fn decode(_: ClientProt, _: &mut Packet) -> IdleTimer { - return IdleTimer::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct IfButton { - #[wasm_bindgen(readonly)] - pub component: u16, -} - -#[wasm_bindgen] -impl IfButton { - #[wasm_bindgen(constructor)] - pub fn new(component: u16) -> IfButton { - return IfButton { - component, - } - } -} - -impl MessageDecoder for IfButton { - fn length() -> i32 { - return 2; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> IfButton { - return IfButton::new(buf.g2()); - } -} - -// ---- - -#[wasm_bindgen] -pub struct IfPlayerDesign { - #[wasm_bindgen(readonly)] - pub gender: u8, - #[wasm_bindgen(getter_with_clone, readonly)] - pub idkit: Vec, - #[wasm_bindgen(getter_with_clone, readonly)] - pub color: Vec, -} - -#[wasm_bindgen] -impl IfPlayerDesign { - #[wasm_bindgen(constructor)] - pub fn new(gender: u8, idkit: Vec, color: Vec) -> IfPlayerDesign { - return IfPlayerDesign { - gender, - idkit, - color, - } - } -} - -impl MessageDecoder for IfPlayerDesign { - fn length() -> i32 { - return 13; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> IfPlayerDesign { - let gender: u8 = buf.g1(); - - let mut idkit: [i32; 7] = [0; 7]; - for i in 0..7 { - let mut v = buf.g1() as i32; - if v == 0xff { - v = -1; - } - unsafe { *idkit.as_mut_ptr().add(i as usize) = v }; - } - - let mut color: [i32; 5] = [0; 5]; - for i in 0..5 { - unsafe { *color.as_mut_ptr().add(i as usize) = buf.g1() as i32 }; - } - - return IfPlayerDesign::new(gender, idkit.to_vec(), color.to_vec()); - } -} - -// ---- - -#[wasm_bindgen] -pub struct IgnoreListAdd { - #[wasm_bindgen(readonly)] - pub username: i64, -} - -#[wasm_bindgen] -impl IgnoreListAdd { - #[wasm_bindgen(constructor)] - pub fn new(username: i64) -> IgnoreListAdd { - return IgnoreListAdd { - username, - } - } -} - -impl MessageDecoder for IgnoreListAdd { - fn length() -> i32 { - return 8; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> IgnoreListAdd { - return IgnoreListAdd::new(buf.g8s()); - } -} - -// ---- - -#[wasm_bindgen] -pub struct IgnoreListDel { - #[wasm_bindgen(readonly)] - pub username: i64, -} - -#[wasm_bindgen] -impl IgnoreListDel { - #[wasm_bindgen(constructor)] - pub fn new(username: i64) -> IgnoreListDel { - return IgnoreListDel { - username, - } - } -} - -impl MessageDecoder for IgnoreListDel { - fn length() -> i32 { - return 8; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> IgnoreListDel { - return IgnoreListDel::new(buf.g8s()); - } -} - -// ---- - -#[wasm_bindgen] -pub struct InvButton { - #[wasm_bindgen(readonly)] - pub op: u8, - #[wasm_bindgen(readonly)] - pub obj: u16, - #[wasm_bindgen(readonly)] - pub slot: u16, - #[wasm_bindgen(readonly)] - pub component: u16, -} - -#[wasm_bindgen] -impl InvButton { - #[wasm_bindgen(constructor)] - pub fn new( - op: u8, - obj: u16, - slot: u16, - component: u16, - ) -> InvButton { - return InvButton { - op, - obj, - slot, - component, - } - } -} - -impl MessageDecoder for InvButton { - fn length() -> i32 { - return 6; - } - - fn decode(prot: ClientProt, buf: &mut Packet) -> InvButton { - let op: u8 = match prot { - ClientProt::INV_BUTTON1 => 1, - ClientProt::INV_BUTTON2 => 2, - ClientProt::INV_BUTTON3 => 3, - ClientProt::INV_BUTTON4 => 4, - ClientProt::INV_BUTTON5 => 5, - _ => 0, - }; - return InvButton::new( - op, - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct InvButtonD { - #[wasm_bindgen(readonly)] - pub component: u16, - #[wasm_bindgen(readonly)] - pub slot: u16, - #[wasm_bindgen(readonly)] - pub target: u16, -} - -#[wasm_bindgen] -impl InvButtonD { - #[wasm_bindgen(constructor)] - pub fn new( - component: u16, - slot: u16, - target: u16, - ) -> InvButtonD { - return InvButtonD { - component, - slot, - target, - } - } -} - -impl MessageDecoder for InvButtonD { - fn length() -> i32 { - return 6; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> InvButtonD { - return InvButtonD::new( - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct MessagePrivate { - #[wasm_bindgen(readonly)] - pub username: i64, - #[wasm_bindgen(getter_with_clone, readonly)] - pub input: Vec, -} - -#[wasm_bindgen] -impl MessagePrivate { - #[wasm_bindgen(constructor)] - pub fn new( - username: i64, - input: Vec, - ) -> MessagePrivate { - return MessagePrivate { - username, - input, - } - } -} - -impl MessageDecoder for MessagePrivate { - fn length() -> i32 { - return -1; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> MessagePrivate { - return MessagePrivate::new( - buf.g8s(), - unsafe { buf.data.get_unchecked(buf.pos..buf.pos + buf.data.len() - 8).to_vec() } - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct MessagePublic { - #[wasm_bindgen(readonly)] - pub color: u8, - #[wasm_bindgen(readonly)] - pub effect: u8, - #[wasm_bindgen(getter_with_clone, readonly)] - pub input: Vec, -} - -#[wasm_bindgen] -impl MessagePublic { - #[wasm_bindgen(constructor)] - pub fn new( - color: u8, - effect: u8, - input: Vec, - ) -> MessagePublic { - return MessagePublic { - color, - effect, - input, - } - } -} - -impl MessageDecoder for MessagePublic { - fn length() -> i32 { - return -1; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> MessagePublic { - return MessagePublic::new( - buf.g1(), - buf.g1(), - unsafe { buf.data.get_unchecked(buf.pos..buf.pos + buf.data.len() - 2).to_vec() } - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct MoveClick { - #[wasm_bindgen(readonly)] - pub ctrl: bool, - #[wasm_bindgen(readonly)] - pub op: bool, - #[wasm_bindgen(getter_with_clone, readonly)] - pub path: Vec, -} - -#[wasm_bindgen] -impl MoveClick { - #[wasm_bindgen(constructor)] - pub fn new( - ctrl: bool, - op: bool, - path: Vec, - ) -> MoveClick { - return MoveClick { - ctrl, - op, - path, - } - } -} - -impl MessageDecoder for MoveClick { - fn length() -> i32 { - return -1; - } - - fn decode(prot: ClientProt, buf: &mut Packet) -> MoveClick { - let ctrl: bool = buf.g1() == 1; - let x: u16 = buf.g2(); - let z: u16 = buf.g2(); - - let offset: usize = if prot == ClientProt::MOVE_MINIMAPCLICK { 14 } else { 0 }; - let waypoints: usize = ((buf.data.len() - buf.pos - offset) / 2) + 1; - - let mut path: Vec = vec![0; waypoints]; - path[0] = CoordGrid::from(x, 0, z).packed; - - for index in 1..waypoints { - if index >= 25 { - break; - } - unsafe { *path.as_mut_ptr().add(index) = CoordGrid::from(x + buf.g1s() as u16, 0, z + buf.g1s() as u16).packed }; - } - - return MoveClick::new( - ctrl, - prot == ClientProt::MOVE_OPCLICK, - path, - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct NoTimeout {} - -#[wasm_bindgen] -impl NoTimeout { - #[wasm_bindgen(constructor)] - pub fn new() -> NoTimeout { - return NoTimeout {}; - } -} - -impl MessageDecoder for NoTimeout { - fn length() -> i32 { - return 0; - } - - fn decode(_: ClientProt, _: &mut Packet) -> NoTimeout { - return NoTimeout::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpHeld { - #[wasm_bindgen(readonly)] - pub op: u8, - #[wasm_bindgen(readonly)] - pub obj: u16, - #[wasm_bindgen(readonly)] - pub slot: u16, - #[wasm_bindgen(readonly)] - pub component: u16, -} - -#[wasm_bindgen] -impl OpHeld { - #[wasm_bindgen(constructor)] - pub fn new( - op: u8, - obj: u16, - slot: u16, - component: u16, - ) -> OpHeld { - return OpHeld { - op, - obj, - slot, - component, - } - } -} - -impl MessageDecoder for OpHeld { - fn length() -> i32 { - return 6; - } - - fn decode(prot: ClientProt, buf: &mut Packet) -> OpHeld { - let op: u8 = match prot { - ClientProt::OPHELD1 => 1, - ClientProt::OPHELD2 => 2, - ClientProt::OPHELD3 => 3, - ClientProt::OPHELD4 => 4, - ClientProt::OPHELD5 => 5, - _ => 0, - }; - return OpHeld::new( - op, - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpHeldT { - #[wasm_bindgen(readonly)] - pub obj: u16, - #[wasm_bindgen(readonly)] - pub slot: u16, - #[wasm_bindgen(readonly)] - pub component: u16, - #[wasm_bindgen(readonly)] - pub spell: u16, -} - -#[wasm_bindgen] -impl OpHeldT { - #[wasm_bindgen(constructor)] - pub fn new( - obj: u16, - slot: u16, - component: u16, - spell: u16, - ) -> OpHeldT { - return OpHeldT { - obj, - slot, - component, - spell, - } - } -} - -impl MessageDecoder for OpHeldT { - fn length() -> i32 { - return 8; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> OpHeldT { - return OpHeldT::new( - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpHeldU { - #[wasm_bindgen(readonly)] - pub obj: u16, - #[wasm_bindgen(readonly)] - pub slot: u16, - #[wasm_bindgen(readonly)] - pub component: u16, - #[wasm_bindgen(readonly, js_name = useObj)] - pub use_obj: u16, - #[wasm_bindgen(readonly, js_name = useSlot)] - pub use_slot: u16, - #[wasm_bindgen(readonly, js_name = useComponent)] - pub use_component: u16, -} - -#[wasm_bindgen] -impl OpHeldU { - #[wasm_bindgen(constructor)] - pub fn new( - obj: u16, - slot: u16, - component: u16, - use_obj: u16, - use_slot: u16, - use_component: u16, - ) -> OpHeldU { - return OpHeldU { - obj, - slot, - component, - use_obj, - use_slot, - use_component, - } - } -} - -impl MessageDecoder for OpHeldU { - fn length() -> i32 { - return 12; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> OpHeldU { - return OpHeldU::new( - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpLoc { - #[wasm_bindgen(readonly)] - pub op: u8, - #[wasm_bindgen(readonly)] - pub x: u16, - #[wasm_bindgen(readonly)] - pub z: u16, - #[wasm_bindgen(readonly)] - pub loc: u16, -} - -#[wasm_bindgen] -impl OpLoc { - #[wasm_bindgen(constructor)] - pub fn new( - op: u8, - x: u16, - z: u16, - loc: u16, - ) -> OpLoc { - return OpLoc { - op, - x, - z, - loc, - } - } -} - -impl MessageDecoder for OpLoc { - fn length() -> i32 { - return 6; - } - - fn decode(prot: ClientProt, buf: &mut Packet) -> OpLoc { - let op: u8 = match prot { - ClientProt::OPLOC1 => 1, - ClientProt::OPLOC2 => 2, - ClientProt::OPLOC3 => 3, - ClientProt::OPLOC4 => 4, - ClientProt::OPLOC5 => 5, - _ => 0, - }; - return OpLoc::new( - op, - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpLocT { - #[wasm_bindgen(readonly)] - pub x: u16, - #[wasm_bindgen(readonly)] - pub z: u16, - #[wasm_bindgen(readonly)] - pub loc: u16, - #[wasm_bindgen(readonly)] - pub spell: u16, -} - -#[wasm_bindgen] -impl OpLocT { - #[wasm_bindgen(constructor)] - pub fn new( - x: u16, - z: u16, - loc: u16, - spell: u16, - ) -> OpLocT { - return OpLocT { - x, - z, - loc, - spell, - } - } -} - -impl MessageDecoder for OpLocT { - fn length() -> i32 { - return 8; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> OpLocT { - return OpLocT::new( - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpLocU { - #[wasm_bindgen(readonly)] - pub x: u16, - #[wasm_bindgen(readonly)] - pub z: u16, - #[wasm_bindgen(readonly)] - pub loc: u16, - #[wasm_bindgen(readonly, js_name = useObj)] - pub use_obj: u16, - #[wasm_bindgen(readonly, js_name = useSlot)] - pub use_slot: u16, - #[wasm_bindgen(readonly, js_name = useComponent)] - pub use_component: u16, -} - -#[wasm_bindgen] -impl OpLocU { - #[wasm_bindgen(constructor)] - pub fn new( - x: u16, - z: u16, - loc: u16, - use_obj: u16, - use_slot: u16, - use_component: u16, - ) -> OpLocU { - return OpLocU { - x, - z, - loc, - use_obj, - use_slot, - use_component, - } - } -} - -impl MessageDecoder for OpLocU { - fn length() -> i32 { - return 12; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> OpLocU { - return OpLocU::new( - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpNpc { - #[wasm_bindgen(readonly)] - pub op: u8, - #[wasm_bindgen(readonly)] - pub nid: u16, -} - -#[wasm_bindgen] -impl OpNpc { - #[wasm_bindgen(constructor)] - pub fn new( - op: u8, - nid: u16, - ) -> OpNpc { - return OpNpc { - op, - nid, - } - } -} - -impl MessageDecoder for OpNpc { - fn length() -> i32 { - return 2; - } - - fn decode(prot: ClientProt, buf: &mut Packet) -> OpNpc { - let op: u8 = match prot { - ClientProt::OPNPC1 => 1, - ClientProt::OPNPC2 => 2, - ClientProt::OPNPC3 => 3, - ClientProt::OPNPC4 => 4, - ClientProt::OPNPC5 => 5, - _ => 0, - }; - return OpNpc::new( - op, - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpNpcT { - #[wasm_bindgen(readonly)] - pub nid: u16, - #[wasm_bindgen(readonly)] - pub spell: u16, -} - -#[wasm_bindgen] -impl OpNpcT { - #[wasm_bindgen(constructor)] - pub fn new( - nid: u16, - spell: u16, - ) -> OpNpcT { - return OpNpcT { - nid, - spell, - } - } -} - -impl MessageDecoder for OpNpcT { - fn length() -> i32 { - return 4; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> OpNpcT { - return OpNpcT::new( - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpNpcU { - #[wasm_bindgen(readonly)] - pub nid: u16, - #[wasm_bindgen(readonly, js_name = useObj)] - pub use_obj: u16, - #[wasm_bindgen(readonly, js_name = useSlot)] - pub use_slot: u16, - #[wasm_bindgen(readonly, js_name = useComponent)] - pub use_component: u16, -} - -#[wasm_bindgen] -impl OpNpcU { - #[wasm_bindgen(constructor)] - pub fn new( - nid: u16, - use_obj: u16, - use_slot: u16, - use_component: u16, - ) -> OpNpcU { - return OpNpcU { - nid, - use_obj, - use_slot, - use_component, - } - } -} - -impl MessageDecoder for OpNpcU { - fn length() -> i32 { - return 8; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> OpNpcU { - return OpNpcU::new( - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpObj { - #[wasm_bindgen(readonly)] - pub op: u8, - #[wasm_bindgen(readonly)] - pub x: u16, - #[wasm_bindgen(readonly)] - pub z: u16, - #[wasm_bindgen(readonly)] - pub obj: u16, -} - -#[wasm_bindgen] -impl OpObj { - #[wasm_bindgen(constructor)] - pub fn new( - op: u8, - x: u16, - z: u16, - obj: u16, - ) -> OpObj { - return OpObj { - op, - x, - z, - obj, - } - } -} - -impl MessageDecoder for OpObj { - fn length() -> i32 { - return 6; - } - - fn decode(prot: ClientProt, buf: &mut Packet) -> OpObj { - let op: u8 = match prot { - ClientProt::OPOBJ1 => 1, - ClientProt::OPOBJ2 => 2, - ClientProt::OPOBJ3 => 3, - ClientProt::OPOBJ4 => 4, - ClientProt::OPOBJ5 => 5, - _ => 0, - }; - return OpObj::new( - op, - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpObjT { - #[wasm_bindgen(readonly)] - pub x: u16, - #[wasm_bindgen(readonly)] - pub z: u16, - #[wasm_bindgen(readonly)] - pub obj: u16, - #[wasm_bindgen(readonly)] - pub spell: u16, -} - -#[wasm_bindgen] -impl OpObjT { - #[wasm_bindgen(constructor)] - pub fn new( - x: u16, - z: u16, - obj: u16, - spell: u16, - ) -> OpObjT { - return OpObjT { - x, - z, - obj, - spell, - } - } -} - -impl MessageDecoder for OpObjT { - fn length() -> i32 { - return 8; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> OpObjT { - return OpObjT::new( - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpObjU { - #[wasm_bindgen(readonly)] - pub x: u16, - #[wasm_bindgen(readonly)] - pub z: u16, - #[wasm_bindgen(readonly)] - pub obj: u16, - #[wasm_bindgen(readonly, js_name = useObj)] - pub use_obj: u16, - #[wasm_bindgen(readonly, js_name = useSlot)] - pub use_slot: u16, - #[wasm_bindgen(readonly, js_name = useComponent)] - pub use_component: u16, -} - -#[wasm_bindgen] -impl OpObjU { - #[wasm_bindgen(constructor)] - pub fn new( - x: u16, - z: u16, - obj: u16, - use_obj: u16, - use_slot: u16, - use_component: u16, - ) -> OpObjU { - return OpObjU { - x, - z, - obj, - use_obj, - use_slot, - use_component, - } - } -} - -impl MessageDecoder for OpObjU { - fn length() -> i32 { - return 12; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> OpObjU { - return OpObjU::new( - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpPlayer { - #[wasm_bindgen(readonly)] - pub op: u8, - #[wasm_bindgen(readonly)] - pub pid: u16, -} - -#[wasm_bindgen] -impl OpPlayer { - #[wasm_bindgen(constructor)] - pub fn new( - op: u8, - pid: u16, - ) -> OpPlayer { - return OpPlayer { - op, - pid, - } - } -} - -impl MessageDecoder for OpPlayer { - fn length() -> i32 { - return 2; - } - - fn decode(prot: ClientProt, buf: &mut Packet) -> OpPlayer { - let op: u8 = match prot { - ClientProt::OPPLAYER1 => 1, - ClientProt::OPPLAYER2 => 2, - ClientProt::OPPLAYER3 => 3, - ClientProt::OPPLAYER4 => 4, - _ => 0, - }; - return OpPlayer::new( - op, - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpPlayerT { - #[wasm_bindgen(readonly)] - pub pid: u16, - #[wasm_bindgen(readonly)] - pub spell: u16, -} - -#[wasm_bindgen] -impl OpPlayerT { - #[wasm_bindgen(constructor)] - pub fn new( - pid: u16, - spell: u16, - ) -> OpPlayerT { - return OpPlayerT { - pid, - spell, - } - } -} - -impl MessageDecoder for OpPlayerT { - fn length() -> i32 { - return 4; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> OpPlayerT { - return OpPlayerT::new( - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct OpPlayerU { - #[wasm_bindgen(readonly)] - pub pid: u16, - #[wasm_bindgen(readonly, js_name = useObj)] - pub use_obj: u16, - #[wasm_bindgen(readonly, js_name = useSlot)] - pub use_slot: u16, - #[wasm_bindgen(readonly, js_name = useComponent)] - pub use_component: u16, -} - -#[wasm_bindgen] -impl OpPlayerU { - #[wasm_bindgen(constructor)] - pub fn new( - pid: u16, - use_obj: u16, - use_slot: u16, - use_component: u16, - ) -> OpPlayerU { - return OpPlayerU { - pid, - use_obj, - use_slot, - use_component, - } - } -} - -impl MessageDecoder for OpPlayerU { - fn length() -> i32 { - return 8; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> OpPlayerU { - return OpPlayerU::new( - buf.g2(), - buf.g2(), - buf.g2(), - buf.g2(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct RebuildGetMaps { - #[wasm_bindgen(getter_with_clone, readonly)] - pub maps: Vec, -} - -#[wasm_bindgen] -impl RebuildGetMaps { - #[wasm_bindgen(constructor)] - pub fn new(maps: Vec) -> RebuildGetMaps { - return RebuildGetMaps { - maps, - } - } -} - -impl MessageDecoder for RebuildGetMaps { - fn length() -> i32 { - return -1; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> RebuildGetMaps { - let mut maps: Vec = vec![0; buf.data.len() / 3]; - for index in 0..maps.len() { - unsafe { *maps.as_mut_ptr().add(index) = buf.g3() as u32 }; - } - return RebuildGetMaps::new(maps); - } -} - -// ---- - -#[wasm_bindgen] -pub struct ResumePauseButton { - #[wasm_bindgen(readonly)] - pub component: u16, -} - -#[wasm_bindgen] -impl ResumePauseButton { - pub fn new(component: u16) -> ResumePauseButton { - return ResumePauseButton { - component, - }; - } -} - -impl MessageDecoder for ResumePauseButton { - fn length() -> i32 { - return 2; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> ResumePauseButton { - return ResumePauseButton::new(buf.g2()); - } -} - -// ---- - -#[wasm_bindgen] -pub struct ResumePCountDialog { - #[wasm_bindgen(readonly)] - pub input: i32, -} - -#[wasm_bindgen] -impl ResumePCountDialog { - #[wasm_bindgen(constructor)] - pub fn new(input: i32) -> ResumePCountDialog { - return ResumePCountDialog { - input, - } - } -} - -impl MessageDecoder for ResumePCountDialog { - fn length() -> i32 { - return 4; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> ResumePCountDialog { - return ResumePCountDialog::new(buf.g4s()); - } -} - -// ---- - -#[wasm_bindgen] -pub struct TutorialClickSide { - #[wasm_bindgen(readonly)] - pub tab: u8, -} - -#[wasm_bindgen] -impl TutorialClickSide { - #[wasm_bindgen(constructor)] - pub fn new(tab: u8) -> TutorialClickSide { - return TutorialClickSide { - tab, - } - } -} - -impl MessageDecoder for TutorialClickSide { - fn length() -> i32 { - return 1; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> TutorialClickSide { - return TutorialClickSide::new(buf.g1()); - } -} - -// ---- - -#[wasm_bindgen] -pub struct ChatSetMode { - #[wasm_bindgen(readonly)] - pub public: u8, - #[wasm_bindgen(readonly)] - pub private: u8, - #[wasm_bindgen(readonly)] - pub trade: u8, -} - -#[wasm_bindgen] -impl ChatSetMode { - #[wasm_bindgen(constructor)] - pub fn new( - public: u8, - private: u8, - trade: u8, - ) -> ChatSetMode { - return ChatSetMode { - public, - private, - trade, - } - } -} - -impl MessageDecoder for ChatSetMode { - fn length() -> i32 { - return 3; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> ChatSetMode { - return ChatSetMode::new( - buf.g1(), - buf.g1(), - buf.g1(), - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct EventTracking { - #[wasm_bindgen(getter_with_clone, readonly)] - pub bytes: Vec, -} - -#[wasm_bindgen] -impl EventTracking { - #[wasm_bindgen(constructor)] - pub fn new(bytes: Vec) -> EventTracking { - return EventTracking { - bytes, - } - } -} - -impl MessageDecoder for EventTracking { - fn length() -> i32 { - return -2; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> EventTracking { - return EventTracking::new(buf.data.clone()); - } -} - -// ---- - -#[wasm_bindgen] -pub struct ReportAbuse { - #[wasm_bindgen(readonly)] - pub offender: i64, - #[wasm_bindgen(readonly)] - pub reason: u8, - #[wasm_bindgen(readonly)] - pub mute: bool, -} - -#[wasm_bindgen] -impl ReportAbuse { - pub fn new( - offender: i64, - reason: u8, - mute: bool, - ) -> ReportAbuse { - return ReportAbuse { - offender, - reason, - mute, - } - } -} - -impl MessageDecoder for ReportAbuse { - fn length() -> i32 { - return 10; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> ReportAbuse { - return ReportAbuse::new( - buf.g8s(), - buf.g1(), - buf.g1() == 1, - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct EventCameraPosition { - #[wasm_bindgen(readonly)] - pub pitch: i32, - #[wasm_bindgen(readonly)] - pub yaw: i32, - #[wasm_bindgen(readonly)] - pub angle: i32, - #[wasm_bindgen(readonly)] - pub zoom: i32, -} - -#[wasm_bindgen] -impl EventCameraPosition { - #[wasm_bindgen(constructor)] - pub fn new( - pitch: i32, - yaw: i32, - angle: i32, - zoom: i32, - ) -> EventCameraPosition { - return EventCameraPosition { - pitch, - yaw, - angle, - zoom, - } - } -} - -impl MessageDecoder for EventCameraPosition { - fn length() -> i32 { - return 6; - } - - fn decode(_: ClientProt, buf: &mut Packet) -> EventCameraPosition { - return EventCameraPosition::new( - buf.g2() as i32, - buf.g2() as i32, - buf.g1() as i32, - buf.g1() as i32, - ); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatOp1 {} - -#[wasm_bindgen] -impl AnticheatOp1 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatOp1 { - return AnticheatOp1 {}; - } -} - -impl MessageDecoder for AnticheatOp1 { - fn length() -> i32 { - return 4; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp1 { - return AnticheatOp1::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatOp2 {} - -#[wasm_bindgen] -impl AnticheatOp2 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatOp2 { - return AnticheatOp2 {}; - } -} - -impl MessageDecoder for AnticheatOp2 { - fn length() -> i32 { - return 4; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp2 { - return AnticheatOp2::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatOp3 {} - -#[wasm_bindgen] -impl AnticheatOp3 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatOp3 { - return AnticheatOp3 {}; - } -} - -impl MessageDecoder for AnticheatOp3 { - fn length() -> i32 { - return 3; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp3 { - return AnticheatOp3::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatOp4 {} - -#[wasm_bindgen] -impl AnticheatOp4 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatOp4 { - return AnticheatOp4 {}; - } -} - -impl MessageDecoder for AnticheatOp4 { - fn length() -> i32 { - return 2; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp4 { - return AnticheatOp4::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatOp5 {} - -#[wasm_bindgen] -impl AnticheatOp5 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatOp5 { - return AnticheatOp5 {}; - } -} - -impl MessageDecoder for AnticheatOp5 { - fn length() -> i32 { - return 0; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp5 { - return AnticheatOp5::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatOp6 {} - -#[wasm_bindgen] -impl AnticheatOp6 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatOp6 { - return AnticheatOp6 {}; - } -} - -impl MessageDecoder for AnticheatOp6 { - fn length() -> i32 { - return 4; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp6 { - return AnticheatOp6::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatOp7 {} - -#[wasm_bindgen] -impl AnticheatOp7 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatOp7 { - return AnticheatOp7 {}; - } -} - -impl MessageDecoder for AnticheatOp7 { - fn length() -> i32 { - return 4; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp7 { - return AnticheatOp7::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatOp8 {} - -#[wasm_bindgen] -impl AnticheatOp8 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatOp8 { - return AnticheatOp8 {}; - } -} - -impl MessageDecoder for AnticheatOp8 { - fn length() -> i32 { - return 2; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp8 { - return AnticheatOp8::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatOp9 {} - -#[wasm_bindgen] -impl AnticheatOp9 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatOp9 { - return AnticheatOp9 {}; - } -} - -impl MessageDecoder for AnticheatOp9 { - fn length() -> i32 { - return 1; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp9 { - return AnticheatOp9::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatCycle1 {} - -#[wasm_bindgen] -impl AnticheatCycle1 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatCycle1 { - return AnticheatCycle1 {}; - } -} - -impl MessageDecoder for AnticheatCycle1 { - fn length() -> i32 { - return 1; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle1 { - return AnticheatCycle1::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatCycle2 {} - -#[wasm_bindgen] -impl AnticheatCycle2 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatCycle2 { - return AnticheatCycle2 {}; - } -} - -impl MessageDecoder for AnticheatCycle2 { - fn length() -> i32 { - return -1; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle2 { - return AnticheatCycle2::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatCycle3 {} - -#[wasm_bindgen] -impl AnticheatCycle3 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatCycle3 { - return AnticheatCycle3 {}; - } -} - -impl MessageDecoder for AnticheatCycle3 { - fn length() -> i32 { - return 3; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle3 { - return AnticheatCycle3::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatCycle4 {} - -#[wasm_bindgen] -impl AnticheatCycle4 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatCycle4 { - return AnticheatCycle4 {}; - } -} - -impl MessageDecoder for AnticheatCycle4 { - fn length() -> i32 { - return 4; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle4 { - return AnticheatCycle4::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatCycle5 {} - -#[wasm_bindgen] -impl AnticheatCycle5 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatCycle5 { - return AnticheatCycle5 {}; - } -} - -impl MessageDecoder for AnticheatCycle5 { - fn length() -> i32 { - return 0; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle5 { - return AnticheatCycle5::new(); - } -} - -// ---- - -#[wasm_bindgen] -pub struct AnticheatCycle6 {} - -#[wasm_bindgen] -impl AnticheatCycle6 { - #[wasm_bindgen(constructor)] - pub fn new() -> AnticheatCycle6 { - return AnticheatCycle6 {}; - } -} - -impl MessageDecoder for AnticheatCycle6 { - fn length() -> i32 { - return -1; - } - - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle6 { - return AnticheatCycle6::new(); - } -} \ No newline at end of file diff --git a/src/out/if_openmain.rs b/src/out/if_openmain.rs new file mode 100644 index 0000000..1c717f3 --- /dev/null +++ b/src/out/if_openmain.rs @@ -0,0 +1,38 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfOpenMain { + component: i32, +} + +impl IfOpenMain { + pub fn new(component:i32) -> IfOpenMain { + return IfOpenMain { + component, + } + } +} + +impl MessageEncoder for IfOpenMain { + fn id(&self) -> i32 { + return ServerInternalProt::IF_OPENMAIN as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/if_openside.rs b/src/out/if_openside.rs new file mode 100644 index 0000000..445b8fa --- /dev/null +++ b/src/out/if_openside.rs @@ -0,0 +1,38 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfOpenSide { + component: i32, +} + +impl IfOpenSide { + pub fn new(component:i32) -> IfOpenSide { + return IfOpenSide { + component, + } + } +} + +impl MessageEncoder for IfOpenSide { + fn id(&self) -> i32 { + return ServerInternalProt::IF_OPENSIDE as i32 + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/message_game.rs b/src/out/message_game.rs new file mode 100644 index 0000000..8176452 --- /dev/null +++ b/src/out/message_game.rs @@ -0,0 +1,38 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct MessageGame { + msg: String, +} + +impl MessageGame { + pub fn new(msg: String) -> MessageGame { + return MessageGame { + msg, + } + } +} + +impl MessageEncoder for MessageGame { + fn id(&self) -> i32 { + return ServerInternalProt::MESSAGE_GAME as i32 + } + + fn length(&self) -> i32 { + return -1; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.pjstr(&self.msg, 10); + } + + fn test(&self) -> usize { + return 1 + self.msg.len(); + } +} \ No newline at end of file diff --git a/src/out/mod.rs b/src/out/mod.rs new file mode 100644 index 0000000..62b23c4 --- /dev/null +++ b/src/out/mod.rs @@ -0,0 +1,5 @@ +pub mod if_openmain; +pub mod if_openside; +pub mod message_game; +pub mod player_info; +pub mod npc_info; \ No newline at end of file diff --git a/src/out/npc_info.rs b/src/out/npc_info.rs new file mode 100644 index 0000000..97c058d --- /dev/null +++ b/src/out/npc_info.rs @@ -0,0 +1,308 @@ +use crate::build::BuildArea; +use crate::coord::CoordGrid; +use crate::grid::ZoneMap; +use crate::message::{NpcInfoFaceCoord, NpcInfoFaceEntity}; +use crate::npc::Npc; +use crate::packet::Packet; +use crate::player::Player; +use crate::prot::NpcInfoProt; +use crate::renderer::NpcRenderer; + +pub struct NpcInfo { + buf: Packet, + updates: Packet, +} + +impl NpcInfo { + const BITS_ADD: usize = 13 + 11 + 5 + 5 + 1; + const BITS_RUN: usize = 1 + 2 + 3 + 3 + 1; + const BITS_WALK: usize = 1 + 2 + 3 + 1; + const BITS_EXTEND: usize = 1 + 2; + + #[inline] + pub fn new() -> NpcInfo { + return NpcInfo { + buf: Packet::new(5000), + updates: Packet::new(5000), + } + } + + #[inline] + pub fn encode( + &mut self, + pos: usize, + renderer: &mut NpcRenderer, + npcs: &mut [Option], + map: &mut ZoneMap, + player: &mut Player, + dx: i32, + dz: i32, + rebuild: bool, + ) -> Vec { + let build: &mut BuildArea = &mut player.build; + + if rebuild || dx > BuildArea::PREFERRED_VIEW_DISTANCE as i32 || dz > BuildArea::PREFERRED_VIEW_DISTANCE as i32 { + build.rebuild_npcs(); + } + + self.buf.pos = 0; + self.buf.bit_pos = 0; + self.updates.pos = 0; + self.updates.bit_pos = 0; + + self.buf.bits(); + let bytes: usize = self.write_npcs(npcs, renderer, player, pos); + self.write_new_npcs(map, npcs, renderer, player, bytes); + if self.updates.pos > 0 { + self.buf.pbit(13, 8191); + self.buf.bytes(); + self.buf.pdata(&self.updates.data, 0, self.updates.pos); + } else { + self.buf.bytes(); + } + return unsafe { self.buf.data.get_unchecked(0..self.buf.pos).to_vec() }; + } + + #[inline] + fn write_npcs( + &mut self, + npcs: &mut [Option], + renderer: &mut NpcRenderer, + player: &mut Player, + mut bytes: usize + ) -> usize { + self.buf.pbit(8, player.build.npcs.len() as i32); + for nid in player.build.npcs.iter() { + match unsafe { &mut *npcs.as_mut_ptr().add(nid as usize) } { + Some(other) => { + if other.nid == -1 || other.tele || other.coord.y() != player.coord.y() || !CoordGrid::within_distance_sw(&player.coord, &other.coord, BuildArea::PREFERRED_VIEW_DISTANCE) || !other.active { + self.remove(player, nid); + other.observers = (other.observers - 1).max(0); + } else { + let len: usize = renderer.highdefinitions(nid); + if other.run_dir != -1 { + self.run(renderer, other, len > 0 && self.fits(bytes + 1, NpcInfo::BITS_RUN, len)); + } else if other.walk_dir != -1 { + self.walk(renderer, other, len > 0 && self.fits(bytes + 1, NpcInfo::BITS_WALK, len)); + } else if len > 0 && self.fits(bytes + 1, NpcInfo::BITS_EXTEND, len) { + self.extend(renderer, other); + } else { + self.idle(); + } + bytes += len + 1; + } + } + _ => self.remove(player, nid), + } + } + return bytes; + } + + #[inline] + fn write_new_npcs( + &mut self, + map: &mut ZoneMap, + npcs: &mut [Option], + renderer: &mut NpcRenderer, + player: &mut Player, + mut bytes: usize + ) { + for nid in player.build.get_nearby_npcs(npcs, map, player.coord.x(), player.coord.y(), player.coord.z()) { + if player.build.npcs.contains(nid) { + continue; + } + if player.build.npcs.len() >= BuildArea::PREFERRED_NPCS as usize { + return; + } + if let Some(other) = unsafe { &mut *npcs.as_mut_ptr().add(nid as usize) } { + let len: usize = renderer.lowdefinitions(nid) + renderer.highdefinitions(nid); + // bits to add npc + extended info size + bits to break loop (13) + if !self.fits(bytes + 1, NpcInfo::BITS_ADD, len) { + // more npcs get added next tick + return; + } + self.add(renderer, player, other, other.nid, other.ntype, other.coord.x() as i32 - player.coord.x() as i32, other.coord.z() as i32 - player.coord.z() as i32); + other.observers = other.observers + 1; + bytes += len + 1; + } + } + } + + #[inline] + fn add( + &mut self, + renderer: &mut NpcRenderer, + player: &mut Player, + other: &Npc, + nid: i32, + ntype: i32, + x: i32, + z: i32, + ) { + self.buf.pbit(13, nid); + self.buf.pbit(11, ntype); + self.buf.pbit(5, x); + self.buf.pbit(5, z); + self.buf.pbit(1, 1); // extend + self.lowdefinition(renderer, other); + player.build.npcs.insert(other.nid); + } + + #[inline] + fn remove( + &mut self, + player: &mut Player, + other: i32 + ) { + self.buf.pbit(1, 1); + self.buf.pbit(2, 3); + player.build.npcs.remove(other); + } + + #[inline] + fn run( + &mut self, + renderer: &mut NpcRenderer, + other: &Npc, + extend: bool + ) { + self.buf.pbit(1, 1); + self.buf.pbit(2, 2); + self.buf.pbit(3, other.walk_dir as i32); + self.buf.pbit(3, other.run_dir as i32); + if extend { + self.buf.pbit(1, 1); + self.highdefinition(renderer, other); + } else { + self.buf.pbit(1, 0); + } + } + + #[inline] + fn walk( + &mut self, + renderer: &mut NpcRenderer, + other: &Npc, + extend: bool + ) { + self.buf.pbit(1, 1); + self.buf.pbit(2, 1); + self.buf.pbit(3, other.walk_dir as i32); + if extend { + self.buf.pbit(1, 1); + self.highdefinition(renderer, other); + } else { + self.buf.pbit(1, 0); + } + } + + #[inline] + fn extend( + &mut self, + renderer: &mut NpcRenderer, + other: &Npc + ) { + self.buf.pbit(1, 1); + self.buf.pbit(2, 0); + self.highdefinition(renderer, other); + } + + #[inline] + fn idle(&mut self) { + self.buf.pbit(1, 0); + } + + #[inline] + fn highdefinition( + &mut self, + renderer: &mut NpcRenderer, + other: &Npc + ) { + self.write_blocks(renderer, other.nid, other.masks); + } + + #[inline] + fn lowdefinition( + &mut self, + renderer: &mut NpcRenderer, + other: &Npc + ) { + let nid: i32 = other.nid; + let mut masks: u32 = other.masks; + + if other.face_entity != -1 && !renderer.has(nid, NpcInfoProt::FACE_ENTITY) { + renderer.cache( + nid, + &NpcInfoFaceEntity::new(other.face_entity), + NpcInfoProt::FACE_ENTITY, + ); + masks |= NpcInfoProt::FACE_ENTITY as u32; + } + + if !renderer.has(nid, NpcInfoProt::FACE_COORD) { + if other.face_x != -1 { + renderer.cache( + nid, + &NpcInfoFaceCoord::new(other.face_x, other.face_z), + NpcInfoProt::FACE_COORD, + ); + } else if other.orientation_x != -1 { + renderer.cache( + nid, + &NpcInfoFaceCoord::new(other.orientation_x, other.orientation_z), + NpcInfoProt::FACE_COORD, + ); + } else { + renderer.cache( + nid, + &NpcInfoFaceCoord::new(CoordGrid::fine(other.coord.x(), 1), CoordGrid::fine(other.coord.z(), 1)), + NpcInfoProt::FACE_COORD, + ); + } + } + + masks |= NpcInfoProt::FACE_COORD as u32; + + self.write_blocks(renderer, nid, masks); + } + + #[inline] + fn write_blocks( + &mut self, + renderer: &mut NpcRenderer, + nid: i32, + masks: u32, + ) { + self.updates.p1((masks & 0xff) as i32); + // ---- + // an optimization *could* be made where all of these are just 1 block of bytes... + // the same could NOT be done for players bcuz of how exact_move works... + if masks & NpcInfoProt::ANIM as u32 != 0 { + renderer.write(&mut self.updates, nid, NpcInfoProt::ANIM); + } + if masks & NpcInfoProt::FACE_ENTITY as u32 != 0 { + renderer.write(&mut self.updates, nid, NpcInfoProt::FACE_ENTITY); + } + if masks & NpcInfoProt::SAY as u32 != 0 { + renderer.write(&mut self.updates, nid, NpcInfoProt::SAY); + } + if masks & NpcInfoProt::DAMAGE as u32 != 0 { + renderer.write(&mut self.updates, nid, NpcInfoProt::DAMAGE); + } + if masks & NpcInfoProt::CHANGE_TYPE as u32 != 0 { + renderer.write(&mut self.updates, nid, NpcInfoProt::CHANGE_TYPE); + } + if masks & NpcInfoProt::SPOT_ANIM as u32 != 0 { + renderer.write(&mut self.updates, nid, NpcInfoProt::SPOT_ANIM); + } + if masks & NpcInfoProt::FACE_COORD as u32 != 0 { + renderer.write(&mut self.updates, nid, NpcInfoProt::FACE_COORD); + } + } + + #[inline] + const fn fits(&self, bytes: usize, bits_to_add: usize, bytes_to_add: usize) -> bool { + // 7 aligns to the next byte + return ((self.buf.bit_pos + bits_to_add + 7) >> 3) + bytes + bytes_to_add <= 4997; + } +} \ No newline at end of file diff --git a/src/info.rs b/src/out/player_info.rs similarity index 57% rename from src/info.rs rename to src/out/player_info.rs index c2bbbd0..8376e91 100644 --- a/src/info.rs +++ b/src/out/player_info.rs @@ -1,12 +1,11 @@ use crate::build::BuildArea; use crate::coord::CoordGrid; use crate::grid::ZoneMap; -use crate::message::{NpcInfoFaceCoord, NpcInfoFaceEntity, PlayerInfoFaceCoord, PlayerInfoFaceEntity}; -use crate::npc::Npc; +use crate::message::{PlayerInfoFaceCoord, PlayerInfoFaceEntity}; use crate::packet::Packet; use crate::player::Player; -use crate::prot::{NpcInfoProt, PlayerInfoProt}; -use crate::renderer::{NpcRenderer, PlayerRenderer}; +use crate::prot::PlayerInfoProt; +use crate::renderer::PlayerRenderer; use crate::visibility::Visibility; use std::collections::HashMap; @@ -401,305 +400,6 @@ impl PlayerInfo { } } - #[inline] - const fn fits(&self, bytes: usize, bits_to_add: usize, bytes_to_add: usize) -> bool { - // 7 aligns to the next byte - return ((self.buf.bit_pos + bits_to_add + 7) >> 3) + bytes + bytes_to_add <= 4997; - } -} - -pub struct NpcInfo { - buf: Packet, - updates: Packet, -} - -impl NpcInfo { - const BITS_ADD: usize = 13 + 11 + 5 + 5 + 1; - const BITS_RUN: usize = 1 + 2 + 3 + 3 + 1; - const BITS_WALK: usize = 1 + 2 + 3 + 1; - const BITS_EXTEND: usize = 1 + 2; - - #[inline] - pub fn new() -> NpcInfo { - return NpcInfo { - buf: Packet::new(5000), - updates: Packet::new(5000), - } - } - - #[inline] - pub fn encode( - &mut self, - pos: usize, - renderer: &mut NpcRenderer, - npcs: &mut [Option], - map: &mut ZoneMap, - player: &mut Player, - dx: i32, - dz: i32, - rebuild: bool, - ) -> Vec { - let build: &mut BuildArea = &mut player.build; - - if rebuild || dx > BuildArea::PREFERRED_VIEW_DISTANCE as i32 || dz > BuildArea::PREFERRED_VIEW_DISTANCE as i32 { - build.rebuild_npcs(); - } - - self.buf.pos = 0; - self.buf.bit_pos = 0; - self.updates.pos = 0; - self.updates.bit_pos = 0; - - self.buf.bits(); - let bytes: usize = self.write_npcs(npcs, renderer, player, pos); - self.write_new_npcs(map, npcs, renderer, player, bytes); - if self.updates.pos > 0 { - self.buf.pbit(13, 8191); - self.buf.bytes(); - self.buf.pdata(&self.updates.data, 0, self.updates.pos); - } else { - self.buf.bytes(); - } - return unsafe { self.buf.data.get_unchecked(0..self.buf.pos).to_vec() }; - } - - #[inline] - fn write_npcs( - &mut self, - npcs: &mut [Option], - renderer: &mut NpcRenderer, - player: &mut Player, - mut bytes: usize - ) -> usize { - self.buf.pbit(8, player.build.npcs.len() as i32); - for nid in player.build.npcs.iter() { - match unsafe { &mut *npcs.as_mut_ptr().add(nid as usize) } { - Some(other) => { - if other.nid == -1 || other.tele || other.coord.y() != player.coord.y() || !CoordGrid::within_distance_sw(&player.coord, &other.coord, BuildArea::PREFERRED_VIEW_DISTANCE) || !other.active { - self.remove(player, nid); - other.observers = (other.observers - 1).max(0); - } else { - let len: usize = renderer.highdefinitions(nid); - if other.run_dir != -1 { - self.run(renderer, other, len > 0 && self.fits(bytes + 1, NpcInfo::BITS_RUN, len)); - } else if other.walk_dir != -1 { - self.walk(renderer, other, len > 0 && self.fits(bytes + 1, NpcInfo::BITS_WALK, len)); - } else if len > 0 && self.fits(bytes + 1, NpcInfo::BITS_EXTEND, len) { - self.extend(renderer, other); - } else { - self.idle(); - } - bytes += len + 1; - } - } - _ => self.remove(player, nid), - } - } - return bytes; - } - - #[inline] - fn write_new_npcs( - &mut self, - map: &mut ZoneMap, - npcs: &mut [Option], - renderer: &mut NpcRenderer, - player: &mut Player, - mut bytes: usize - ) { - for nid in player.build.get_nearby_npcs(npcs, map, player.coord.x(), player.coord.y(), player.coord.z()) { - if player.build.npcs.contains(nid) { - continue; - } - if player.build.npcs.len() >= BuildArea::PREFERRED_NPCS as usize { - return; - } - if let Some(other) = unsafe { &mut *npcs.as_mut_ptr().add(nid as usize) } { - let len: usize = renderer.lowdefinitions(nid) + renderer.highdefinitions(nid); - // bits to add npc + extended info size + bits to break loop (13) - if !self.fits(bytes + 1, NpcInfo::BITS_ADD, len) { - // more npcs get added next tick - return; - } - self.add(renderer, player, other, other.nid, other.ntype, other.coord.x() as i32 - player.coord.x() as i32, other.coord.z() as i32 - player.coord.z() as i32); - other.observers = other.observers + 1; - bytes += len + 1; - } - } - } - - #[inline] - fn add( - &mut self, - renderer: &mut NpcRenderer, - player: &mut Player, - other: &Npc, - nid: i32, - ntype: i32, - x: i32, - z: i32, - ) { - self.buf.pbit(13, nid); - self.buf.pbit(11, ntype); - self.buf.pbit(5, x); - self.buf.pbit(5, z); - self.buf.pbit(1, 1); // extend - self.lowdefinition(renderer, other); - player.build.npcs.insert(other.nid); - } - - #[inline] - fn remove( - &mut self, - player: &mut Player, - other: i32 - ) { - self.buf.pbit(1, 1); - self.buf.pbit(2, 3); - player.build.npcs.remove(other); - } - - #[inline] - fn run( - &mut self, - renderer: &mut NpcRenderer, - other: &Npc, - extend: bool - ) { - self.buf.pbit(1, 1); - self.buf.pbit(2, 2); - self.buf.pbit(3, other.walk_dir as i32); - self.buf.pbit(3, other.run_dir as i32); - if extend { - self.buf.pbit(1, 1); - self.highdefinition(renderer, other); - } else { - self.buf.pbit(1, 0); - } - } - - #[inline] - fn walk( - &mut self, - renderer: &mut NpcRenderer, - other: &Npc, - extend: bool - ) { - self.buf.pbit(1, 1); - self.buf.pbit(2, 1); - self.buf.pbit(3, other.walk_dir as i32); - if extend { - self.buf.pbit(1, 1); - self.highdefinition(renderer, other); - } else { - self.buf.pbit(1, 0); - } - } - - #[inline] - fn extend( - &mut self, - renderer: &mut NpcRenderer, - other: &Npc - ) { - self.buf.pbit(1, 1); - self.buf.pbit(2, 0); - self.highdefinition(renderer, other); - } - - #[inline] - fn idle(&mut self) { - self.buf.pbit(1, 0); - } - - #[inline] - fn highdefinition( - &mut self, - renderer: &mut NpcRenderer, - other: &Npc - ) { - self.write_blocks(renderer, other.nid, other.masks); - } - - #[inline] - fn lowdefinition( - &mut self, - renderer: &mut NpcRenderer, - other: &Npc - ) { - let nid: i32 = other.nid; - let mut masks: u32 = other.masks; - - if other.face_entity != -1 && !renderer.has(nid, NpcInfoProt::FACE_ENTITY) { - renderer.cache( - nid, - &NpcInfoFaceEntity::new(other.face_entity), - NpcInfoProt::FACE_ENTITY, - ); - masks |= NpcInfoProt::FACE_ENTITY as u32; - } - - if !renderer.has(nid, NpcInfoProt::FACE_COORD) { - if other.face_x != -1 { - renderer.cache( - nid, - &NpcInfoFaceCoord::new(other.face_x, other.face_z), - NpcInfoProt::FACE_COORD, - ); - } else if other.orientation_x != -1 { - renderer.cache( - nid, - &NpcInfoFaceCoord::new(other.orientation_x, other.orientation_z), - NpcInfoProt::FACE_COORD, - ); - } else { - renderer.cache( - nid, - &NpcInfoFaceCoord::new(CoordGrid::fine(other.coord.x(), 1), CoordGrid::fine(other.coord.z(), 1)), - NpcInfoProt::FACE_COORD, - ); - } - } - - masks |= NpcInfoProt::FACE_COORD as u32; - - self.write_blocks(renderer, nid, masks); - } - - #[inline] - fn write_blocks( - &mut self, - renderer: &mut NpcRenderer, - nid: i32, - masks: u32, - ) { - self.updates.p1((masks & 0xff) as i32); - // ---- - // an optimization *could* be made where all of these are just 1 block of bytes... - // the same could NOT be done for players bcuz of how exact_move works... - if masks & NpcInfoProt::ANIM as u32 != 0 { - renderer.write(&mut self.updates, nid, NpcInfoProt::ANIM); - } - if masks & NpcInfoProt::FACE_ENTITY as u32 != 0 { - renderer.write(&mut self.updates, nid, NpcInfoProt::FACE_ENTITY); - } - if masks & NpcInfoProt::SAY as u32 != 0 { - renderer.write(&mut self.updates, nid, NpcInfoProt::SAY); - } - if masks & NpcInfoProt::DAMAGE as u32 != 0 { - renderer.write(&mut self.updates, nid, NpcInfoProt::DAMAGE); - } - if masks & NpcInfoProt::CHANGE_TYPE as u32 != 0 { - renderer.write(&mut self.updates, nid, NpcInfoProt::CHANGE_TYPE); - } - if masks & NpcInfoProt::SPOT_ANIM as u32 != 0 { - renderer.write(&mut self.updates, nid, NpcInfoProt::SPOT_ANIM); - } - if masks & NpcInfoProt::FACE_COORD as u32 != 0 { - renderer.write(&mut self.updates, nid, NpcInfoProt::FACE_COORD); - } - } - #[inline] const fn fits(&self, bytes: usize, bits_to_add: usize, bytes_to_add: usize) -> bool { // 7 aligns to the next byte From 982ff2b778445ab29b66784e64fd35d7a93e1443 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 30 Mar 2025 20:20:20 -0400 Subject: [PATCH 03/14] feat: outgoing packets --- src/coord.rs | 10 + src/lib.rs | 1087 ++++++++++++++++++++--- src/message.rs | 1 + src/out/cam_lookat.rs | 56 ++ src/out/cam_moveto.rs | 56 ++ src/out/cam_reset.rs | 32 + src/out/cam_shake.rs | 52 ++ src/out/chat_filter_settings.rs | 48 + src/out/count_dialog.rs | 32 + src/out/data_land.rs | 98 ++ src/out/data_loc.rs | 98 ++ src/out/enable_tracking.rs | 32 + src/out/finish_tracking.rs | 32 + src/out/hint_arrow.rs | 85 ++ src/out/if_close.rs | 32 + src/out/if_openchat.rs | 38 + src/out/if_openmainside.rs | 44 + src/out/if_setanim.rs | 44 + src/out/if_setcolour.rs | 44 + src/out/if_sethide.rs | 44 + src/out/if_setmodel.rs | 44 + src/out/if_setnpchead.rs | 44 + src/out/if_setobject.rs | 48 + src/out/if_setplayerhead.rs | 40 + src/out/if_setposition.rs | 48 + src/out/if_setrecol.rs | 48 + src/out/if_settab.rs | 44 + src/out/if_settabactive.rs | 40 + src/out/if_settext.rs | 44 + src/out/last_login_info.rs | 52 ++ src/out/loc_addchange.rs | 51 ++ src/out/loc_anim.rs | 51 ++ src/out/loc_del.rs | 47 + src/out/loc_merge.rs | 85 ++ src/out/logout.rs | 32 + src/out/map_anim.rs | 52 ++ src/out/map_projanim.rs | 86 ++ src/out/message_private.rs | 58 ++ src/out/midi_jingle.rs | 44 + src/out/midi_song.rs | 48 + src/out/mod.rs | 66 +- src/out/obj_add.rs | 48 + src/out/obj_count.rs | 52 ++ src/out/obj_del.rs | 44 + src/out/obj_reveal.rs | 52 ++ src/out/rebuild_normal.rs | 67 ++ src/out/reset_anims.rs | 32 + src/out/reset_clientvarcache.rs | 32 + src/out/set_multiway.rs | 38 + src/out/synth_sound.rs | 48 + src/out/tut_flash.rs | 40 + src/out/tut_open.rs | 40 + src/out/unset_map_flag.rs | 32 + src/out/update_friendlist.rs | 41 + src/out/update_ignorelist.rs | 40 + src/out/update_inv_full.rs | 82 ++ src/out/update_inv_partial.rs | 82 ++ src/out/update_inv_stop_transmit.rs | 40 + src/out/update_pid.rs | 40 + src/out/update_reboot_timer.rs | 40 + src/out/update_runenergy.rs | 40 + src/out/update_runweight.rs | 40 + src/out/update_stat.rs | 48 + src/out/update_zone_full_follows.rs | 51 ++ src/out/update_zone_partial_enclosed.rs | 55 ++ src/out/update_zone_partial_follows.rs | 51 ++ src/out/varp_large.rs | 44 + src/out/varp_small.rs | 44 + src/pack.rs | 119 +++ src/player.rs | 16 +- src/prot.rs | 11 + 71 files changed, 4333 insertions(+), 113 deletions(-) create mode 100644 src/out/cam_lookat.rs create mode 100644 src/out/cam_moveto.rs create mode 100644 src/out/cam_reset.rs create mode 100644 src/out/cam_shake.rs create mode 100644 src/out/chat_filter_settings.rs create mode 100644 src/out/count_dialog.rs create mode 100644 src/out/data_land.rs create mode 100644 src/out/data_loc.rs create mode 100644 src/out/enable_tracking.rs create mode 100644 src/out/finish_tracking.rs create mode 100644 src/out/hint_arrow.rs create mode 100644 src/out/if_close.rs create mode 100644 src/out/if_openchat.rs create mode 100644 src/out/if_openmainside.rs create mode 100644 src/out/if_setanim.rs create mode 100644 src/out/if_setcolour.rs create mode 100644 src/out/if_sethide.rs create mode 100644 src/out/if_setmodel.rs create mode 100644 src/out/if_setnpchead.rs create mode 100644 src/out/if_setobject.rs create mode 100644 src/out/if_setplayerhead.rs create mode 100644 src/out/if_setposition.rs create mode 100644 src/out/if_setrecol.rs create mode 100644 src/out/if_settab.rs create mode 100644 src/out/if_settabactive.rs create mode 100644 src/out/if_settext.rs create mode 100644 src/out/last_login_info.rs create mode 100644 src/out/loc_addchange.rs create mode 100644 src/out/loc_anim.rs create mode 100644 src/out/loc_del.rs create mode 100644 src/out/loc_merge.rs create mode 100644 src/out/logout.rs create mode 100644 src/out/map_anim.rs create mode 100644 src/out/map_projanim.rs create mode 100644 src/out/message_private.rs create mode 100644 src/out/midi_jingle.rs create mode 100644 src/out/midi_song.rs create mode 100644 src/out/obj_add.rs create mode 100644 src/out/obj_count.rs create mode 100644 src/out/obj_del.rs create mode 100644 src/out/obj_reveal.rs create mode 100644 src/out/rebuild_normal.rs create mode 100644 src/out/reset_anims.rs create mode 100644 src/out/reset_clientvarcache.rs create mode 100644 src/out/set_multiway.rs create mode 100644 src/out/synth_sound.rs create mode 100644 src/out/tut_flash.rs create mode 100644 src/out/tut_open.rs create mode 100644 src/out/unset_map_flag.rs create mode 100644 src/out/update_friendlist.rs create mode 100644 src/out/update_ignorelist.rs create mode 100644 src/out/update_inv_full.rs create mode 100644 src/out/update_inv_partial.rs create mode 100644 src/out/update_inv_stop_transmit.rs create mode 100644 src/out/update_pid.rs create mode 100644 src/out/update_reboot_timer.rs create mode 100644 src/out/update_runenergy.rs create mode 100644 src/out/update_runweight.rs create mode 100644 src/out/update_stat.rs create mode 100644 src/out/update_zone_full_follows.rs create mode 100644 src/out/update_zone_partial_enclosed.rs create mode 100644 src/out/update_zone_partial_follows.rs create mode 100644 src/out/varp_large.rs create mode 100644 src/out/varp_small.rs create mode 100644 src/pack.rs diff --git a/src/coord.rs b/src/coord.rs index 823d476..4980c6d 100644 --- a/src/coord.rs +++ b/src/coord.rs @@ -47,4 +47,14 @@ impl CoordGrid { pub const fn zone(pos: u16) -> u16 { return pos >> 3; } + + #[inline] + pub const fn origin(pos: u16) -> u16 { + return ((pos >> 3) - 6) << 3; + } + + #[inline] + pub const fn pack_zone_coord(x: u16, z: u16) -> u8 { + return (((x & 0x7) as u8) << 4) | (z & 0x7) as u8; + } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 8791965..179be79 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,13 +4,78 @@ use crate::coord::CoordGrid; use crate::grid::ZoneMap; use crate::message::{IncomingPacket, MessageDecoder, OutgoingPacket}; use crate::npc::Npc; +use crate::out::cam_lookat::CamLookAt; +use crate::out::cam_moveto::CamMoveTo; +use crate::out::cam_reset::CamReset; +use crate::out::cam_shake::CamShake; +use crate::out::chat_filter_settings::ChatFilterSettings; +use crate::out::count_dialog::PCountDialog; +use crate::out::data_land::{DataLand, DataLandDone}; +use crate::out::data_loc::{DataLoc, DataLocDone}; +use crate::out::enable_tracking::EnableTracking; +use crate::out::finish_tracking::FinishTracking; +use crate::out::hint_arrow::HintArrow; +use crate::out::if_close::IfClose; +use crate::out::if_openchat::IfOpenChat; use crate::out::if_openmain::IfOpenMain; +use crate::out::if_openmainside::IfOpenMainSide; use crate::out::if_openside::IfOpenSide; +use crate::out::if_setanim::IfSetAnim; +use crate::out::if_setcolour::IfSetColour; +use crate::out::if_sethide::IfSetHide; +use crate::out::if_setmodel::IfSetModel; +use crate::out::if_setnpchead::IfSetNpcHead; +use crate::out::if_setobject::IfSetObject; +use crate::out::if_setplayerhead::IfSetPlayerHead; +use crate::out::if_setposition::IfSetPosition; +use crate::out::if_setrecol::IfSetRecol; +use crate::out::if_settab::IfSetTab; +use crate::out::if_settabactive::IfSetTabActive; +use crate::out::if_settext::IfSetText; +use crate::out::last_login_info::LastLoginInfo; +use crate::out::loc_addchange::LocAddChange; +use crate::out::loc_anim::LocAnim; +use crate::out::loc_del::LocDel; +use crate::out::loc_merge::LocMerge; +use crate::out::logout::Logout; +use crate::out::map_anim::MapAnim; +use crate::out::map_projanim::MapProjAnim; use crate::out::message_game::MessageGame; +use crate::out::message_private::MessagePrivateOut; +use crate::out::midi_jingle::MidiJingle; +use crate::out::midi_song::MidiSong; use crate::out::npc_info::NpcInfo; +use crate::out::obj_add::ObjAdd; +use crate::out::obj_count::ObjCount; +use crate::out::obj_del::ObjDel; +use crate::out::obj_reveal::ObjReveal; +use crate::out::rebuild_normal::RebuildNormal; +use crate::out::reset_anims::ResetAnims; +use crate::out::reset_clientvarcache::ResetClientVarCache; +use crate::out::set_multiway::SetMultiway; +use crate::out::synth_sound::SynthSound; +use crate::out::tut_flash::TutFlash; +use crate::out::tut_open::TutOpen; +use crate::out::unset_map_flag::UnsetMapFlag; +use crate::out::update_friendlist::UpdateFriendList; +use crate::out::update_ignorelist::UpdateIgnoreList; +use crate::out::update_inv_full::UpdateInvFull; +use crate::out::update_inv_partial::UpdateInvPartial; +use crate::out::update_inv_stop_transmit::UpdateInvStopTransmit; +use crate::out::update_pid::UpdatePid; +use crate::out::update_reboot_timer::UpdateRebootTimer; +use crate::out::update_runenergy::UpdateRunEnergy; +use crate::out::update_runweight::UpdateRunWeight; +use crate::out::update_stat::UpdateStat; +use crate::out::update_zone_full_follows::UpdateZoneFullFollows; +use crate::out::update_zone_partial_enclosed::UpdateZonePartialEnclosed; +use crate::out::update_zone_partial_follows::UpdateZonePartialFollows; +use crate::out::varp_large::VarpLarge; +use crate::out::varp_small::VarpSmall; +use crate::pack::WordPack; use crate::packet::Packet; use crate::player::{Chat, ExactMove, Player}; -use crate::prot::{ClientInternalProt, ClientProt}; +use crate::prot::{ClientInternalProt, ClientProt, ServerInternalProt}; use crate::r#in::anticheat::{AnticheatCycle1, AnticheatCycle2, AnticheatCycle3, AnticheatCycle4, AnticheatCycle5, AnticheatCycle6, AnticheatOp1, AnticheatOp2, AnticheatOp3, AnticheatOp4, AnticheatOp5, AnticheatOp6, AnticheatOp7, AnticheatOp8, AnticheatOp9}; use crate::r#in::chat_setmode::ChatSetMode; use crate::r#in::client_cheat::ClientCheat; @@ -59,6 +124,7 @@ mod priority; mod category; mod r#in; mod out; +mod pack; static mut PLAYERS: Lazy>> = Lazy::new(|| vec![None; 2048]); static mut PLAYER_GRID: Lazy>> = Lazy::new(|| HashMap::with_capacity(2048)); @@ -188,22 +254,26 @@ pub unsafe fn compute_player( } #[wasm_bindgen(js_name = playerInfo)] -pub unsafe fn player_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option> { +pub unsafe fn player_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option { if pid == -1 { return None; } if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return Some(PLAYER_INFO.encode( - pos, - &mut **addr_of_mut!(PLAYER_RENDERER), - &**addr_of!(PLAYERS), - &mut **addr_of_mut!(ZONE_MAP), - &**addr_of!(PLAYER_GRID), - player, - dx, - dz, - rebuild, + return Some(OutgoingPacket::new( + Some(PLAYER_INFO.encode( + pos, + &mut **addr_of_mut!(PLAYER_RENDERER), + &**addr_of!(PLAYERS), + &mut **addr_of_mut!(ZONE_MAP), + &**addr_of!(PLAYER_GRID), + player, + dx, + dz, + rebuild, + )), + ServerInternalProt::PLAYER_INFO as i32, + -2, )); } @@ -316,21 +386,25 @@ pub unsafe fn compute_npc( } #[wasm_bindgen(js_name = npcInfo)] -pub unsafe fn npc_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option> { +pub unsafe fn npc_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option { if pid == -1 { return None; } if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return Some(NPC_INFO.encode( - pos, - &mut **addr_of_mut!(NPC_RENDERER), - &mut **addr_of_mut!(NPCS), - &mut **addr_of_mut!(ZONE_MAP), - player, - dx, - dz, - rebuild + return Some(OutgoingPacket::new( + Some(NPC_INFO.encode( + pos, + &mut **addr_of_mut!(NPC_RENDERER), + &mut **addr_of_mut!(NPCS), + &mut **addr_of_mut!(ZONE_MAP), + player, + dx, + dz, + rebuild + )), + ServerInternalProt::NPC_INFO as i32, + -2, )); } @@ -409,6 +483,201 @@ pub unsafe fn cleanup_player_buildarea(pid: i32) { // ---- encoders +#[wasm_bindgen(js_name = camLookAt)] +pub unsafe fn cam_lookat(pid: i32, x: i32, z: i32, height: i32, speed: i32, multiplier: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&CamLookAt::new(x, z, height, speed, multiplier)); + } + + return None; +} + +#[wasm_bindgen(js_name = camMoveTo)] +pub unsafe fn cam_moveto(pid: i32, x: i32, z: i32, height: i32, speed: i32, multiplier: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&CamMoveTo::new(x, z, height, speed, multiplier)); + } + + return None; +} + +#[wasm_bindgen(js_name = camReset)] +pub unsafe fn cam_reset(pid: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&CamReset::new()); + } + + return None; +} + +#[wasm_bindgen(js_name = camShake)] +pub unsafe fn cam_shake(pid: i32, shake: i32, jitter: i32, amplitude: i32, frequency: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&CamShake::new(shake, jitter, amplitude, frequency)); + } + + return None; +} + +#[wasm_bindgen(js_name = chatFilterSettings)] +pub unsafe fn chat_filter_settings(pid: i32, public: i32, private: i32, trade: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&ChatFilterSettings::new(public, private, trade)); + } + + return None; +} + +#[wasm_bindgen(js_name = countDialog)] +pub unsafe fn count_dialog(pid: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&PCountDialog::new()); + } + + return None; +} + +#[wasm_bindgen(js_name = dataLand)] +pub unsafe fn data_land(pid: i32, x: i32, z: i32, offset: i32, length: i32, data: Vec) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&DataLand::new(x, z, offset, length, data)); + } + + return None; +} + +#[wasm_bindgen(js_name = dataLandDone)] +pub unsafe fn data_land_done(pid: i32, x: i32, z: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&DataLandDone::new(x, z)); + } + + return None; +} + +#[wasm_bindgen(js_name = dataLoc)] +pub unsafe fn data_loc(pid: i32, x: i32, z: i32, offset: i32, length: i32, data: Vec) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&DataLoc::new(x, z, offset, length, data)); + } + + return None; +} + +#[wasm_bindgen(js_name = dataLocDone)] +pub unsafe fn data_loc_done(pid: i32, x: i32, z: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&DataLocDone::new(x, z)); + } + + return None; +} + +#[wasm_bindgen(js_name = enableTracking)] +pub unsafe fn enable_tracking(pid: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&EnableTracking::new()); + } + + return None; +} + +#[wasm_bindgen(js_name = finishTracking)] +pub unsafe fn finish_tracking(pid: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&FinishTracking::new()); + } + + return None; +} + +#[wasm_bindgen(js_name = hintArrow)] +pub unsafe fn hint_arrow(pid: i32, arrow: i32, nid: i32, pid2: i32, x: i32, z: i32, y: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&HintArrow::new(arrow, nid, pid2, x, z, y)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifClose)] +pub unsafe fn if_close(pid: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfClose::new()); + } + + return None; +} + +#[wasm_bindgen(js_name = ifOpenChat)] +pub unsafe fn if_open_chat(pid: i32, component: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfOpenChat::new(component)); + } + + return None; +} + #[wasm_bindgen(js_name = ifOpenMain)] pub unsafe fn if_open_main(pid: i32, component: i32) -> Option { if pid == -1 { @@ -416,33 +685,607 @@ pub unsafe fn if_open_main(pid: i32, component: i32) -> Option { } if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfOpenMain::new(component)); + return player.write(&IfOpenMain::new(component)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifOpenMainSide)] +pub unsafe fn if_open_main_side(pid: i32, main: i32, side: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfOpenMainSide::new(main, side)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifOpenSide)] +pub unsafe fn if_open_side(pid: i32, component: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfOpenSide::new(component)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetAnim)] +pub unsafe fn if_setanim(pid: i32, component: i32, seq: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetAnim::new(component, seq)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetColour)] +pub unsafe fn if_setcolour(pid: i32, component: i32, colour: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetColour::new(component, colour)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetHide)] +pub unsafe fn if_sethide(pid: i32, component: i32, hidden: bool) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetHide::new(component, hidden)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetModel)] +pub unsafe fn if_setmodel(pid: i32, component: i32, model: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetModel::new(component, model)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetNpcHead)] +pub unsafe fn if_setnpchead(pid: i32, component: i32, npc: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetNpcHead::new(component, npc)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetObject)] +pub unsafe fn if_setobject(pid: i32, component: i32, obj: i32, scale: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetObject::new(component, obj, scale)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetPlayerHead)] +pub unsafe fn if_setplayerhead(pid: i32, component: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetPlayerHead::new(component)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetPosition)] +pub unsafe fn if_setposition(pid: i32, component: i32, x: i32, y: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetPosition::new(component, x, y)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetRecol)] +pub unsafe fn if_setrecol(pid: i32, component: i32, src: i32, dst: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetRecol::new(component, src, dst)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetTab)] +pub unsafe fn if_settab(pid: i32, component: i32, tab: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetTab::new(component, tab)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetTabActive)] +pub unsafe fn if_settabactive(pid: i32, tab: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetTabActive::new(tab)); + } + + return None; +} + +#[wasm_bindgen(js_name = ifSetText)] +pub unsafe fn if_settext(pid: i32, component: i32, text: String) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&IfSetText::new(component, text)); + } + + return None; +} + +#[wasm_bindgen(js_name = lastLoginInfo)] +pub unsafe fn last_login_info(pid: i32, lastIp: i32, daysSinceLogin: i32, daysSinceRecovery: i32, messages: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&LastLoginInfo::new(lastIp, daysSinceLogin, daysSinceRecovery, messages)); + } + + return None; +} + +#[wasm_bindgen(js_name = locAddChange)] +pub unsafe fn loc_addchange(coord: i32, loc: i32, shape: i32, angle: i32, enclose: bool) -> Option { + return Player::write_zone_message(&LocAddChange::new(coord, loc, shape, angle), enclose); +} + +#[wasm_bindgen(js_name = locAnim)] +pub unsafe fn loc_anim(coord: i32, shape: i32, angle: i32, seq: i32, enclose: bool) -> Option { + return Player::write_zone_message(&LocAnim::new(coord, shape, angle, seq), enclose); +} + +#[wasm_bindgen(js_name = locDel)] +pub unsafe fn loc_del(coord: i32, shape: i32, angle: i32, enclose: bool) -> Option { + return Player::write_zone_message(&LocDel::new(coord, shape, angle), enclose); +} + +#[wasm_bindgen(js_name = locMerge)] +pub unsafe fn loc_merge(srcX: i32, srcZ: i32, shape: i32, angle: i32, loc: i32, start: i32, end: i32, pid: i32, east: i32, south: i32, west: i32, north: i32, enclose: bool) -> Option { + return Player::write_zone_message(&LocMerge::new(srcX, srcZ, shape, angle, loc, start, end, pid, east, south, west, north), enclose); +} + +#[wasm_bindgen(js_name = logout)] +pub unsafe fn logout(pid: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&Logout::new()); + } + + return None; +} + +#[wasm_bindgen(js_name = mapAnim)] +pub unsafe fn map_anim(coord: i32, spotanim: i32, height: i32, delay: i32, enclose: bool) -> Option { + return Player::write_zone_message(&MapAnim::new(coord, spotanim, height, delay), enclose); +} + +#[wasm_bindgen(js_name = mapProjAnim)] +pub unsafe fn map_projanim(srcX: i32, srcZ: i32, dstX: i32, dstZ: i32, target: i32, spotanim: i32, srcHeight: i32, dstHeight: i32, start: i32, end: i32, peak: i32, arc: i32, enclose: bool) -> Option { + return Player::write_zone_message(&MapProjAnim::new(srcX, srcZ, dstX, dstZ, target, spotanim, srcHeight, dstHeight, start, end, peak, arc), enclose); +} + +#[wasm_bindgen(js_name = messageGame)] +pub unsafe fn message_game(pid: i32, msg: String) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&MessageGame::new(msg)); } return None; } -#[wasm_bindgen(js_name = ifOpenSide)] -pub unsafe fn if_open_side(pid: i32, component: i32) -> Option { +#[wasm_bindgen(js_name = messagePrivateOut)] +pub unsafe fn message_private_out(pid: i32, from: i64, id: i32, staffModLevel: i32, msg: String) -> Option { if pid == -1 { return None; } if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfOpenSide::new(component)); + return player.write(&MessagePrivateOut::new(from, id, staffModLevel, msg)); } return None; } -#[wasm_bindgen(js_name = messageGame)] -pub unsafe fn message_game(pid: i32, msg: String) -> Option { +#[wasm_bindgen(js_name = midiJingle)] +pub unsafe fn midi_jingle(pid: i32, delay: i32, data: Vec) -> Option { if pid == -1 { return None; } if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&MessageGame::new(msg)); + return player.write(&MidiJingle::new(delay, data)); + } + + return None; +} + +#[wasm_bindgen(js_name = midiSong)] +pub unsafe fn midi_song(pid: i32, name: String, crc: i32, length: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&MidiSong::new(name, crc, length)); + } + + return None; +} + +#[wasm_bindgen(js_name = objAdd)] +pub unsafe fn obj_add(coord: i32, obj: i32, count: i32, enclose: bool) -> Option { + return Player::write_zone_message(&ObjAdd::new(coord, obj, count), enclose); +} + +#[wasm_bindgen(js_name = objCount)] +pub unsafe fn obj_count(coord: i32, obj: i32, oldCount: i32, newCount: i32, enclose: bool) -> Option { + return Player::write_zone_message(&ObjCount::new(coord, obj, oldCount, newCount), enclose); +} + +#[wasm_bindgen(js_name = objDel)] +pub unsafe fn obj_del(coord: i32, obj: i32, enclose: bool) -> Option { + return Player::write_zone_message(&ObjDel::new(coord, obj), enclose); +} + +#[wasm_bindgen(js_name = objReveal)] +pub unsafe fn obj_reveal(coord: i32, obj: i32, count: i32, receiver: i32, enclose: bool) -> Option { + return Player::write_zone_message(&ObjReveal::new(coord, obj, count, receiver), enclose); +} + +#[wasm_bindgen(js_name = rebuildNormal)] +pub unsafe fn rebuild_normal(pid: i32, x: i32, z: i32, squares: Vec, maps: Vec, locs: Vec) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&RebuildNormal::new(x, z, squares, maps, locs)); + } + + return None; +} + +#[wasm_bindgen(js_name = resetAnims)] +pub unsafe fn reset_anims(pid: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&ResetAnims::new()); + } + + return None; +} + +#[wasm_bindgen(js_name = resetClientVarCache)] +pub unsafe fn reset_clientvarcache(pid: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&ResetClientVarCache::new()); + } + + return None; +} + +#[wasm_bindgen(js_name = setMultiway)] +pub unsafe fn set_multiway(pid: i32, hidden: bool) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&SetMultiway::new(hidden)); + } + + return None; +} + +#[wasm_bindgen(js_name = synthSound)] +pub unsafe fn synth_sound(pid: i32, synth: i32, loops: i32, delay: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&SynthSound::new(synth, loops, delay)); + } + + return None; +} + +#[wasm_bindgen(js_name = tutFlash)] +pub unsafe fn tut_flash(pid: i32, tab: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&TutFlash::new(tab)); + } + + return None; +} + +#[wasm_bindgen(js_name = tutOpen)] +pub unsafe fn tut_open(pid: i32, component: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&TutOpen::new(component)); + } + + return None; +} + +#[wasm_bindgen(js_name = unsetMapFlag)] +pub unsafe fn unset_map_flag(pid: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UnsetMapFlag::new()); + } + + return None; +} + +#[wasm_bindgen(js_name = updateFriendList)] +pub unsafe fn update_friendlist(pid: i32, name: i64, node: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateFriendList::new(name, node)); + } + + return None; +} + +#[wasm_bindgen(js_name = updateIgnoreList)] +pub unsafe fn update_ignorelist(pid: i32, names: Vec) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateIgnoreList::new(names)); + } + + return None; +} + +#[wasm_bindgen(js_name = updateInvFull)] +pub unsafe fn update_inv_full(pid: i32, size: i32, component: i32, objs: Vec) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateInvFull::new(size, component, objs)); + } + + return None; +} + +#[wasm_bindgen(js_name = updateInvPartial)] +pub unsafe fn update_inv_partial(pid: i32, component: i32, slots: Vec, objs: Vec) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateInvPartial::new(component, slots, objs)); + } + + return None; +} + +#[wasm_bindgen(js_name = updateInvStopTransmit)] +pub unsafe fn update_inv_stop_transmit(pid: i32, component: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateInvStopTransmit::new(component)); + } + + return None; +} + +#[wasm_bindgen(js_name = updatePid)] +pub unsafe fn update_pid(pid: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdatePid::new(pid)); + } + + return None; +} + +#[wasm_bindgen(js_name = updateRebootTimer)] +pub unsafe fn update_reboot_timer(pid: i32, ticks: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateRebootTimer::new(ticks)); + } + + return None; +} + +#[wasm_bindgen(js_name = updateRunEnergy)] +pub unsafe fn update_runenergy(pid: i32, energy: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateRunEnergy::new(energy)); + } + + return None; +} + +#[wasm_bindgen(js_name = updateRunWeight)] +pub unsafe fn update_runweight(pid: i32, kg: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateRunWeight::new(kg)); + } + + return None; +} + +#[wasm_bindgen(js_name = updateStat)] +pub unsafe fn update_stat(pid: i32, stat: i32, experience: i32, level: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateStat::new(stat, experience, level)); + } + + return None; +} + +#[wasm_bindgen(js_name = updateZoneFullFollows)] +pub unsafe fn update_zone_full_follows(pid: i32, x: i32, z: i32, originX: i32, originZ: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateZoneFullFollows::new(x, z, originX, originZ)); + } + + return None; +} + +#[wasm_bindgen(js_name = updateZonePartialEnclosed)] +pub unsafe fn update_zone_partial_enclosed(pid: i32, x: i32, z: i32, originX: i32, originZ: i32, data: Vec) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateZonePartialEnclosed::new(x, z, originX, originZ, data)); + } + + return None; +} + +#[wasm_bindgen(js_name = updateZonePartialFollows)] +pub unsafe fn update_zone_partial_follows(pid: i32, x: i32, z: i32, originX: i32, originZ: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return player.write(&UpdateZonePartialFollows::new(x, z, originX, originZ)); + } + + return None; +} + +#[wasm_bindgen(js_name = varp)] +pub unsafe fn varp(pid: i32, varp: i32, value: i32) -> Option { + if pid == -1 { + return None; + } + + if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { + return if value >= -128 && value <= 127 { + player.write(&VarpSmall::new(varp, value)) + } else { + player.write(&VarpLarge::new(varp, value)) + } } return None; @@ -463,90 +1306,98 @@ pub unsafe fn next_buffered_write(pid: i32) -> Option { // ---- decoders +static PACKET_LOOKUP: Lazy>> = Lazy::new(|| { + use ClientInternalProt::*; + use ClientProt::*; + + let mut lookup: HashMap> = HashMap::new(); + lookup.insert(ClientInternalProt::CLIENT_CHEAT as i32, Some(IncomingPacket::new(ClientProt::CLIENT_CHEAT as i32, ClientCheat::length()))); + lookup.insert(ClientInternalProt::CLOSE_MODAL as i32, Some(IncomingPacket::new(ClientProt::CLOSE_MODAL as i32, CloseModal::length()))); + lookup.insert(ClientInternalProt::FRIENDLIST_ADD as i32, Some(IncomingPacket::new(ClientProt::FRIENDLIST_ADD as i32, FriendListAdd::length()))); + lookup.insert(ClientInternalProt::FRIENDLIST_DEL as i32, Some(IncomingPacket::new(ClientProt::FRIENDLIST_DEL as i32, FriendListDel::length()))); + lookup.insert(ClientInternalProt::IDLE_TIMER as i32, Some(IncomingPacket::new(ClientProt::IDLE_TIMER as i32, IdleTimer::length()))); + lookup.insert(ClientInternalProt::IF_BUTTON as i32, Some(IncomingPacket::new(ClientProt::IF_BUTTON as i32, IfButton::length()))); + lookup.insert(ClientInternalProt::IF_PLAYERDESIGN as i32, Some(IncomingPacket::new(ClientProt::IF_PLAYERDESIGN as i32, IfPlayerDesign::length()))); + lookup.insert(ClientInternalProt::IGNORELIST_ADD as i32, Some(IncomingPacket::new(ClientProt::IGNORELIST_ADD as i32, IgnoreListAdd::length()))); + lookup.insert(ClientInternalProt::IGNORELIST_DEL as i32, Some(IncomingPacket::new(ClientProt::IGNORELIST_DEL as i32, IgnoreListDel::length()))); + lookup.insert(ClientInternalProt::INV_BUTTON1 as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTON1 as i32, InvButton::length()))); + lookup.insert(ClientInternalProt::INV_BUTTON2 as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTON2 as i32, InvButton::length()))); + lookup.insert(ClientInternalProt::INV_BUTTON3 as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTON3 as i32, InvButton::length()))); + lookup.insert(ClientInternalProt::INV_BUTTON4 as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTON4 as i32, InvButton::length()))); + lookup.insert(ClientInternalProt::INV_BUTTON5 as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTON5 as i32, InvButton::length()))); + lookup.insert(ClientInternalProt::INV_BUTTOND as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTOND as i32, InvButtonD::length()))); + lookup.insert(ClientInternalProt::MESSAGE_PRIVATE as i32, Some(IncomingPacket::new(ClientProt::MESSAGE_PRIVATE as i32, MessagePrivate::length()))); + lookup.insert(ClientInternalProt::MESSAGE_PUBLIC as i32, Some(IncomingPacket::new(ClientProt::MESSAGE_PUBLIC as i32, MessagePublic::length()))); + lookup.insert(ClientInternalProt::MOVE_MINIMAPCLICK as i32, Some(IncomingPacket::new(ClientProt::MOVE_MINIMAPCLICK as i32, MoveClick::length()))); + lookup.insert(ClientInternalProt::MOVE_GAMECLICK as i32, Some(IncomingPacket::new(ClientProt::MOVE_GAMECLICK as i32, MoveClick::length()))); + lookup.insert(ClientInternalProt::MOVE_OPCLICK as i32, Some(IncomingPacket::new(ClientProt::MOVE_OPCLICK as i32, MoveClick::length()))); + lookup.insert(ClientInternalProt::NO_TIMEOUT as i32, Some(IncomingPacket::new(ClientProt::NO_TIMEOUT as i32, NoTimeout::length()))); + lookup.insert(ClientInternalProt::OPHELD1 as i32, Some(IncomingPacket::new(ClientProt::OPHELD1 as i32, OpHeld::length()))); + lookup.insert(ClientInternalProt::OPHELD2 as i32, Some(IncomingPacket::new(ClientProt::OPHELD2 as i32, OpHeld::length()))); + lookup.insert(ClientInternalProt::OPHELD3 as i32, Some(IncomingPacket::new(ClientProt::OPHELD3 as i32, OpHeld::length()))); + lookup.insert(ClientInternalProt::OPHELD4 as i32, Some(IncomingPacket::new(ClientProt::OPHELD4 as i32, OpHeld::length()))); + lookup.insert(ClientInternalProt::OPHELD5 as i32, Some(IncomingPacket::new(ClientProt::OPHELD5 as i32, OpHeld::length()))); + lookup.insert(ClientInternalProt::OPHELDT as i32, Some(IncomingPacket::new(ClientProt::OPHELDT as i32, OpHeldT::length()))); + lookup.insert(ClientInternalProt::OPHELDU as i32, Some(IncomingPacket::new(ClientProt::OPHELDU as i32, OpHeldU::length()))); + lookup.insert(ClientInternalProt::OPLOC1 as i32, Some(IncomingPacket::new(ClientProt::OPLOC1 as i32, OpLoc::length()))); + lookup.insert(ClientInternalProt::OPLOC2 as i32, Some(IncomingPacket::new(ClientProt::OPLOC2 as i32, OpLoc::length()))); + lookup.insert(ClientInternalProt::OPLOC3 as i32, Some(IncomingPacket::new(ClientProt::OPLOC3 as i32, OpLoc::length()))); + lookup.insert(ClientInternalProt::OPLOC4 as i32, Some(IncomingPacket::new(ClientProt::OPLOC4 as i32, OpLoc::length()))); + lookup.insert(ClientInternalProt::OPLOC5 as i32, Some(IncomingPacket::new(ClientProt::OPLOC5 as i32, OpLoc::length()))); + lookup.insert(ClientInternalProt::OPLOCT as i32, Some(IncomingPacket::new(ClientProt::OPLOCT as i32, OpLocT::length()))); + lookup.insert(ClientInternalProt::OPLOCU as i32, Some(IncomingPacket::new(ClientProt::OPLOCU as i32, OpLocU::length()))); + lookup.insert(ClientInternalProt::OPNPC1 as i32, Some(IncomingPacket::new(ClientProt::OPNPC1 as i32, OpNpc::length()))); + lookup.insert(ClientInternalProt::OPNPC2 as i32, Some(IncomingPacket::new(ClientProt::OPNPC2 as i32, OpNpc::length()))); + lookup.insert(ClientInternalProt::OPNPC3 as i32, Some(IncomingPacket::new(ClientProt::OPNPC3 as i32, OpNpc::length()))); + lookup.insert(ClientInternalProt::OPNPC4 as i32, Some(IncomingPacket::new(ClientProt::OPNPC4 as i32, OpNpc::length()))); + lookup.insert(ClientInternalProt::OPNPC5 as i32, Some(IncomingPacket::new(ClientProt::OPNPC5 as i32, OpNpc::length()))); + lookup.insert(ClientInternalProt::OPNPCT as i32, Some(IncomingPacket::new(ClientProt::OPNPCT as i32, OpNpcT::length()))); + lookup.insert(ClientInternalProt::OPNPCU as i32, Some(IncomingPacket::new(ClientProt::OPNPCU as i32, OpNpcU::length()))); + lookup.insert(ClientInternalProt::OPOBJ1 as i32, Some(IncomingPacket::new(ClientProt::OPOBJ1 as i32, OpObj::length()))); + lookup.insert(ClientInternalProt::OPOBJ2 as i32, Some(IncomingPacket::new(ClientProt::OPOBJ2 as i32, OpObj::length()))); + lookup.insert(ClientInternalProt::OPOBJ3 as i32, Some(IncomingPacket::new(ClientProt::OPOBJ3 as i32, OpObj::length()))); + lookup.insert(ClientInternalProt::OPOBJ4 as i32, Some(IncomingPacket::new(ClientProt::OPOBJ4 as i32, OpObj::length()))); + lookup.insert(ClientInternalProt::OPOBJ5 as i32, Some(IncomingPacket::new(ClientProt::OPOBJ5 as i32, OpObj::length()))); + lookup.insert(ClientInternalProt::OPOBJT as i32, Some(IncomingPacket::new(ClientProt::OPOBJT as i32, OpObjT::length()))); + lookup.insert(ClientInternalProt::OPOBJU as i32, Some(IncomingPacket::new(ClientProt::OPOBJU as i32, OpObjU::length()))); + lookup.insert(ClientInternalProt::OPPLAYER1 as i32, Some(IncomingPacket::new(ClientProt::OPPLAYER1 as i32, OpPlayer::length()))); + lookup.insert(ClientInternalProt::OPPLAYER2 as i32, Some(IncomingPacket::new(ClientProt::OPPLAYER2 as i32, OpPlayer::length()))); + lookup.insert(ClientInternalProt::OPPLAYER3 as i32, Some(IncomingPacket::new(ClientProt::OPPLAYER3 as i32, OpPlayer::length()))); + lookup.insert(ClientInternalProt::OPPLAYER4 as i32, Some(IncomingPacket::new(ClientProt::OPPLAYER4 as i32, OpPlayer::length()))); + lookup.insert(ClientInternalProt::OPPLAYERT as i32, Some(IncomingPacket::new(ClientProt::OPPLAYERT as i32, OpPlayerT::length()))); + lookup.insert(ClientInternalProt::OPPLAYERU as i32, Some(IncomingPacket::new(ClientProt::OPPLAYERU as i32, OpPlayerU::length()))); + lookup.insert(ClientInternalProt::REBUILD_GETMAPS as i32, Some(IncomingPacket::new(ClientProt::REBUILD_GETMAPS as i32, RebuildGetMaps::length()))); + lookup.insert(ClientInternalProt::RESUME_PAUSEBUTTON as i32, Some(IncomingPacket::new(ClientProt::RESUME_PAUSEBUTTON as i32, ResumePauseButton::length()))); + lookup.insert(ClientInternalProt::RESUME_P_COUNTDIALOG as i32, Some(IncomingPacket::new(ClientProt::RESUME_P_COUNTDIALOG as i32, ResumePCountDialog::length()))); + lookup.insert(ClientInternalProt::TUTORIAL_CLICKSIDE as i32, Some(IncomingPacket::new(ClientProt::TUTORIAL_CLICKSIDE as i32, TutorialClickSide::length()))); + lookup.insert(ClientInternalProt::CHAT_SETMODE as i32, Some(IncomingPacket::new(ClientProt::CHAT_SETMODE as i32, ChatSetMode::length()))); + lookup.insert(ClientInternalProt::EVENT_TRACKING as i32, Some(IncomingPacket::new(ClientProt::EVENT_TRACKING as i32, EventTracking::length()))); + lookup.insert(ClientInternalProt::REPORT_ABUSE as i32, Some(IncomingPacket::new(ClientProt::REPORT_ABUSE as i32, ReportAbuse::length()))); + lookup.insert(ClientInternalProt::EVENT_CAMERA_POSITION as i32, Some(IncomingPacket::new(ClientProt::EVENT_CAMERA_POSITION as i32, EventCameraPosition::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC1 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC1 as i32, AnticheatOp1::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC2 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC2 as i32, AnticheatOp2::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC3 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC3 as i32, AnticheatOp3::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC4 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC4 as i32, AnticheatOp4::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC5 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC5 as i32, AnticheatOp5::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC6 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC6 as i32, AnticheatOp6::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC7 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC7 as i32, AnticheatOp7::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC8 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC8 as i32, AnticheatOp8::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC9 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC9 as i32, AnticheatOp9::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC1 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC1 as i32, AnticheatCycle1::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC2 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC2 as i32, AnticheatCycle2::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC3 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC3 as i32, AnticheatCycle3::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC4 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC4 as i32, AnticheatCycle4::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC5 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC5 as i32, AnticheatCycle5::length()))); + lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC6 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC6 as i32, AnticheatCycle6::length()))); + return lookup; +}); + #[wasm_bindgen(js_name = nextBufferedRead)] pub unsafe fn next_buffered_read(id: i32) -> Option { - return match id { - n if n == ClientInternalProt::CLIENT_CHEAT as i32 => Some(IncomingPacket::new(ClientProt::CLIENT_CHEAT as i32, ClientCheat::length())), - n if n == ClientInternalProt::CLOSE_MODAL as i32 => Some(IncomingPacket::new(ClientProt::CLOSE_MODAL as i32, CloseModal::length())), - n if n == ClientInternalProt::FRIENDLIST_ADD as i32 => Some(IncomingPacket::new(ClientProt::FRIENDLIST_ADD as i32, FriendListAdd::length())), - n if n == ClientInternalProt::FRIENDLIST_DEL as i32 => Some(IncomingPacket::new(ClientProt::FRIENDLIST_DEL as i32, FriendListDel::length())), - n if n == ClientInternalProt::IDLE_TIMER as i32 => Some(IncomingPacket::new(ClientProt::IDLE_TIMER as i32, IdleTimer::length())), - n if n == ClientInternalProt::IF_BUTTON as i32 => Some(IncomingPacket::new(ClientProt::IF_BUTTON as i32, IfButton::length())), - n if n == ClientInternalProt::IF_PLAYERDESIGN as i32 => Some(IncomingPacket::new(ClientProt::IF_PLAYERDESIGN as i32, IfPlayerDesign::length())), - n if n == ClientInternalProt::IGNORELIST_ADD as i32 => Some(IncomingPacket::new(ClientProt::IGNORELIST_ADD as i32, IgnoreListAdd::length())), - n if n == ClientInternalProt::IGNORELIST_DEL as i32 => Some(IncomingPacket::new(ClientProt::IGNORELIST_DEL as i32, IgnoreListDel::length())), - n if n == ClientInternalProt::INV_BUTTON1 as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTON1 as i32, InvButton::length())), - n if n == ClientInternalProt::INV_BUTTON2 as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTON2 as i32, InvButton::length())), - n if n == ClientInternalProt::INV_BUTTON3 as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTON3 as i32, InvButton::length())), - n if n == ClientInternalProt::INV_BUTTON4 as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTON4 as i32, InvButton::length())), - n if n == ClientInternalProt::INV_BUTTON5 as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTON5 as i32, InvButton::length())), - n if n == ClientInternalProt::INV_BUTTOND as i32 => Some(IncomingPacket::new(ClientProt::INV_BUTTOND as i32, InvButtonD::length())), - n if n == ClientInternalProt::MESSAGE_PRIVATE as i32 => Some(IncomingPacket::new(ClientProt::MESSAGE_PRIVATE as i32, MessagePrivate::length())), - n if n == ClientInternalProt::MESSAGE_PUBLIC as i32 => Some(IncomingPacket::new(ClientProt::MESSAGE_PUBLIC as i32, MessagePublic::length())), - n if n == ClientInternalProt::MOVE_MINIMAPCLICK as i32 => Some(IncomingPacket::new(ClientProt::MOVE_MINIMAPCLICK as i32, MoveClick::length())), - n if n == ClientInternalProt::MOVE_GAMECLICK as i32 => Some(IncomingPacket::new(ClientProt::MOVE_GAMECLICK as i32, MoveClick::length())), - n if n == ClientInternalProt::MOVE_OPCLICK as i32 => Some(IncomingPacket::new(ClientProt::MOVE_OPCLICK as i32, MoveClick::length())), - n if n == ClientInternalProt::NO_TIMEOUT as i32 => Some(IncomingPacket::new(ClientProt::NO_TIMEOUT as i32, NoTimeout::length())), - n if n == ClientInternalProt::OPHELD1 as i32 => Some(IncomingPacket::new(ClientProt::OPHELD1 as i32, OpHeld::length())), - n if n == ClientInternalProt::OPHELD2 as i32 => Some(IncomingPacket::new(ClientProt::OPHELD2 as i32, OpHeld::length())), - n if n == ClientInternalProt::OPHELD3 as i32 => Some(IncomingPacket::new(ClientProt::OPHELD3 as i32, OpHeld::length())), - n if n == ClientInternalProt::OPHELD4 as i32 => Some(IncomingPacket::new(ClientProt::OPHELD4 as i32, OpHeld::length())), - n if n == ClientInternalProt::OPHELD5 as i32 => Some(IncomingPacket::new(ClientProt::OPHELD5 as i32, OpHeld::length())), - n if n == ClientInternalProt::OPHELDT as i32 => Some(IncomingPacket::new(ClientProt::OPHELDT as i32, OpHeldT::length())), - n if n == ClientInternalProt::OPHELDU as i32 => Some(IncomingPacket::new(ClientProt::OPHELDU as i32, OpHeldU::length())), - n if n == ClientInternalProt::OPLOC1 as i32 => Some(IncomingPacket::new(ClientProt::OPLOC1 as i32, OpLoc::length())), - n if n == ClientInternalProt::OPLOC2 as i32 => Some(IncomingPacket::new(ClientProt::OPLOC2 as i32, OpLoc::length())), - n if n == ClientInternalProt::OPLOC3 as i32 => Some(IncomingPacket::new(ClientProt::OPLOC3 as i32, OpLoc::length())), - n if n == ClientInternalProt::OPLOC4 as i32 => Some(IncomingPacket::new(ClientProt::OPLOC4 as i32, OpLoc::length())), - n if n == ClientInternalProt::OPLOC5 as i32 => Some(IncomingPacket::new(ClientProt::OPLOC5 as i32, OpLoc::length())), - n if n == ClientInternalProt::OPLOCT as i32 => Some(IncomingPacket::new(ClientProt::OPLOCT as i32, OpLocT::length())), - n if n == ClientInternalProt::OPLOCU as i32 => Some(IncomingPacket::new(ClientProt::OPLOCU as i32, OpLocU::length())), - n if n == ClientInternalProt::OPNPC1 as i32 => Some(IncomingPacket::new(ClientProt::OPNPC1 as i32, OpNpc::length())), - n if n == ClientInternalProt::OPNPC2 as i32 => Some(IncomingPacket::new(ClientProt::OPNPC2 as i32, OpNpc::length())), - n if n == ClientInternalProt::OPNPC3 as i32 => Some(IncomingPacket::new(ClientProt::OPNPC3 as i32, OpNpc::length())), - n if n == ClientInternalProt::OPNPC4 as i32 => Some(IncomingPacket::new(ClientProt::OPNPC4 as i32, OpNpc::length())), - n if n == ClientInternalProt::OPNPC5 as i32 => Some(IncomingPacket::new(ClientProt::OPNPC5 as i32, OpNpc::length())), - n if n == ClientInternalProt::OPNPCT as i32 => Some(IncomingPacket::new(ClientProt::OPNPCT as i32, OpNpcT::length())), - n if n == ClientInternalProt::OPNPCU as i32 => Some(IncomingPacket::new(ClientProt::OPNPCU as i32, OpNpcU::length())), - n if n == ClientInternalProt::OPOBJ1 as i32 => Some(IncomingPacket::new(ClientProt::OPOBJ1 as i32, OpObj::length())), - n if n == ClientInternalProt::OPOBJ2 as i32 => Some(IncomingPacket::new(ClientProt::OPOBJ2 as i32, OpObj::length())), - n if n == ClientInternalProt::OPOBJ3 as i32 => Some(IncomingPacket::new(ClientProt::OPOBJ3 as i32, OpObj::length())), - n if n == ClientInternalProt::OPOBJ4 as i32 => Some(IncomingPacket::new(ClientProt::OPOBJ4 as i32, OpObj::length())), - n if n == ClientInternalProt::OPOBJ5 as i32 => Some(IncomingPacket::new(ClientProt::OPOBJ5 as i32, OpObj::length())), - n if n == ClientInternalProt::OPOBJT as i32 => Some(IncomingPacket::new(ClientProt::OPOBJT as i32, OpObjT::length())), - n if n == ClientInternalProt::OPOBJU as i32 => Some(IncomingPacket::new(ClientProt::OPOBJU as i32, OpObjU::length())), - n if n == ClientInternalProt::OPPLAYER1 as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYER1 as i32, OpPlayer::length())), - n if n == ClientInternalProt::OPPLAYER2 as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYER2 as i32, OpPlayer::length())), - n if n == ClientInternalProt::OPPLAYER3 as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYER3 as i32, OpPlayer::length())), - n if n == ClientInternalProt::OPPLAYER4 as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYER4 as i32, OpPlayer::length())), - n if n == ClientInternalProt::OPPLAYERT as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYERT as i32, OpPlayerT::length())), - n if n == ClientInternalProt::OPPLAYERU as i32 => Some(IncomingPacket::new(ClientProt::OPPLAYERU as i32, OpPlayerU::length())), - n if n == ClientInternalProt::REBUILD_GETMAPS as i32 => Some(IncomingPacket::new(ClientProt::REBUILD_GETMAPS as i32, RebuildGetMaps::length())), - n if n == ClientInternalProt::RESUME_PAUSEBUTTON as i32 => Some(IncomingPacket::new(ClientProt::RESUME_PAUSEBUTTON as i32, ResumePauseButton::length())), - n if n == ClientInternalProt::RESUME_P_COUNTDIALOG as i32 => Some(IncomingPacket::new(ClientProt::RESUME_P_COUNTDIALOG as i32, ResumePCountDialog::length())), - n if n == ClientInternalProt::TUTORIAL_CLICKSIDE as i32 => Some(IncomingPacket::new(ClientProt::TUTORIAL_CLICKSIDE as i32, TutorialClickSide::length())), - n if n == ClientInternalProt::CHAT_SETMODE as i32 => Some(IncomingPacket::new(ClientProt::CHAT_SETMODE as i32, ChatSetMode::length())), - n if n == ClientInternalProt::EVENT_TRACKING as i32 => Some(IncomingPacket::new(ClientProt::EVENT_TRACKING as i32, EventTracking::length())), - n if n == ClientInternalProt::REPORT_ABUSE as i32 => Some(IncomingPacket::new(ClientProt::REPORT_ABUSE as i32, ReportAbuse::length())), - n if n == ClientInternalProt::EVENT_CAMERA_POSITION as i32 => Some(IncomingPacket::new(ClientProt::EVENT_CAMERA_POSITION as i32, EventCameraPosition::length())), - n if n == ClientInternalProt::ANTICHEAT_OPLOGIC1 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC1 as i32, AnticheatOp1::length())), - n if n == ClientInternalProt::ANTICHEAT_OPLOGIC2 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC2 as i32, AnticheatOp2::length())), - n if n == ClientInternalProt::ANTICHEAT_OPLOGIC3 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC3 as i32, AnticheatOp3::length())), - n if n == ClientInternalProt::ANTICHEAT_OPLOGIC4 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC4 as i32, AnticheatOp4::length())), - n if n == ClientInternalProt::ANTICHEAT_OPLOGIC5 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC5 as i32, AnticheatOp5::length())), - n if n == ClientInternalProt::ANTICHEAT_OPLOGIC6 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC6 as i32, AnticheatOp6::length())), - n if n == ClientInternalProt::ANTICHEAT_OPLOGIC7 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC7 as i32, AnticheatOp7::length())), - n if n == ClientInternalProt::ANTICHEAT_OPLOGIC8 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC8 as i32, AnticheatOp8::length())), - n if n == ClientInternalProt::ANTICHEAT_OPLOGIC9 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC9 as i32, AnticheatOp9::length())), - n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC1 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC1 as i32, AnticheatCycle1::length())), - n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC2 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC2 as i32, AnticheatCycle2::length())), - n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC3 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC3 as i32, AnticheatCycle3::length())), - n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC4 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC4 as i32, AnticheatCycle4::length())), - n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC5 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC5 as i32, AnticheatCycle5::length())), - n if n == ClientInternalProt::ANTICHEAT_CYCLELOGIC6 as i32 => Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC6 as i32, AnticheatCycle6::length())), - - _ => None, - }; + return match PACKET_LOOKUP.get(&id) { + None => None, + Some(packet) => packet.clone(), + } } unsafe fn read(bytes: Vec) -> Packet { @@ -945,3 +1796,17 @@ pub unsafe fn anticheatcycle5(bytes: Vec) -> Option { pub unsafe fn anticheatcycle6(bytes: Vec) -> Option { return Some(AnticheatCycle6::decode(ClientProt::ANTICHEAT_CYCLELOGIC6, &mut read(bytes))); } + +// ---- misc + +#[wasm_bindgen(js_name = unpackWords)] +pub unsafe fn unpack_words(bytes: Vec, length: usize) -> String { + return WordPack::unpack(&mut Packet::from(bytes), length); +} + +#[wasm_bindgen(js_name = packWords)] +pub unsafe fn pack_words(bytes: Vec, msg: String) -> Vec { + let mut buf: Packet = Packet::from(bytes); + WordPack::pack(&mut buf, msg); + return buf.data; +} diff --git a/src/message.rs b/src/message.rs index 0404a83..c9af920 100644 --- a/src/message.rs +++ b/src/message.rs @@ -47,6 +47,7 @@ impl OutgoingPacket { } #[wasm_bindgen] +#[derive(Clone)] pub struct IncomingPacket { #[wasm_bindgen(readonly)] pub id: i32, diff --git a/src/out/cam_lookat.rs b/src/out/cam_lookat.rs new file mode 100644 index 0000000..0c2802d --- /dev/null +++ b/src/out/cam_lookat.rs @@ -0,0 +1,56 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct CamLookAt { + x: i32, + z: i32, + height: i32, + speed: i32, + multiplier: i32, +} + +impl CamLookAt { + pub fn new( + x: i32, + z: i32, + height: i32, + speed: i32, + multiplier: i32, + ) -> CamLookAt { + return CamLookAt { + x, + z, + height, + speed, + multiplier, + } + } +} + +impl MessageEncoder for CamLookAt { + fn id(&self) -> i32 { + return ServerInternalProt::CAM_LOOKAT as i32; + } + + fn length(&self) -> i32 { + return 6; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.x); + buf.p1(self.z); + buf.p2(self.height); + buf.p1(self.speed); + buf.p1(self.multiplier); + } + + fn test(&self) -> usize { + return 6; + } +} \ No newline at end of file diff --git a/src/out/cam_moveto.rs b/src/out/cam_moveto.rs new file mode 100644 index 0000000..e8f7c1f --- /dev/null +++ b/src/out/cam_moveto.rs @@ -0,0 +1,56 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct CamMoveTo { + x: i32, + z: i32, + height: i32, + speed: i32, + multiplier: i32, +} + +impl CamMoveTo { + pub fn new( + x: i32, + z: i32, + height: i32, + speed: i32, + multiplier: i32, + ) -> CamMoveTo { + return CamMoveTo { + x, + z, + height, + speed, + multiplier, + } + } +} + +impl MessageEncoder for CamMoveTo { + fn id(&self) -> i32 { + return ServerInternalProt::CAM_MOVETO as i32; + } + + fn length(&self) -> i32 { + return 6; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.x); + buf.p1(self.z); + buf.p2(self.height); + buf.p1(self.speed); + buf.p1(self.multiplier); + } + + fn test(&self) -> usize { + return 6; + } +} \ No newline at end of file diff --git a/src/out/cam_reset.rs b/src/out/cam_reset.rs new file mode 100644 index 0000000..827fee4 --- /dev/null +++ b/src/out/cam_reset.rs @@ -0,0 +1,32 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct CamReset {} + +impl CamReset { + pub fn new() -> CamReset { + return CamReset {} + } +} + +impl MessageEncoder for CamReset { + fn id(&self) -> i32 { + return ServerInternalProt::CAM_RESET as i32; + } + + fn length(&self) -> i32 { + return 0; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, _: &mut Packet) {} + + fn test(&self) -> usize { + return 0; + } +} \ No newline at end of file diff --git a/src/out/cam_shake.rs b/src/out/cam_shake.rs new file mode 100644 index 0000000..3ed4e24 --- /dev/null +++ b/src/out/cam_shake.rs @@ -0,0 +1,52 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct CamShake { + shake: i32, + jitter: i32, + amplitude: i32, + frequency: i32, +} + +impl CamShake { + pub fn new( + shake: i32, + jitter: i32, + amplitude: i32, + frequency: i32, + ) -> CamShake { + return CamShake { + shake, + jitter, + amplitude, + frequency, + } + } +} + +impl MessageEncoder for CamShake { + fn id(&self) -> i32 { + return ServerInternalProt::CAM_SHAKE as i32; + } + + fn length(&self) -> i32 { + return 4; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.shake); // direction? + buf.p1(self.jitter); + buf.p1(self.amplitude); + buf.p1(self.frequency); + } + + fn test(&self) -> usize { + return 4; + } +} \ No newline at end of file diff --git a/src/out/chat_filter_settings.rs b/src/out/chat_filter_settings.rs new file mode 100644 index 0000000..e2f7436 --- /dev/null +++ b/src/out/chat_filter_settings.rs @@ -0,0 +1,48 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct ChatFilterSettings { + public: i32, + private: i32, + trade: i32, +} + +impl ChatFilterSettings { + pub fn new( + public: i32, + private: i32, + trade: i32, + ) -> ChatFilterSettings { + return ChatFilterSettings { + public, + private, + trade, + } + } +} + +impl MessageEncoder for ChatFilterSettings { + fn id(&self) -> i32 { + return ServerInternalProt::CHAT_FILTER_SETTINGS as i32; + } + + fn length(&self) -> i32 { + return 3; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.public); + buf.p1(self.private); + buf.p1(self.trade); + } + + fn test(&self) -> usize { + return 3; + } +} \ No newline at end of file diff --git a/src/out/count_dialog.rs b/src/out/count_dialog.rs new file mode 100644 index 0000000..15aafc3 --- /dev/null +++ b/src/out/count_dialog.rs @@ -0,0 +1,32 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct PCountDialog {} + +impl PCountDialog { + pub fn new() -> PCountDialog { + return PCountDialog {} + } +} + +impl MessageEncoder for PCountDialog { + fn id(&self) -> i32 { + return ServerInternalProt::P_COUNTDIALOG as i32; + } + + fn length(&self) -> i32 { + return 0; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, _: &mut Packet) {} + + fn test(&self) -> usize { + return 0; + } +} \ No newline at end of file diff --git a/src/out/data_land.rs b/src/out/data_land.rs new file mode 100644 index 0000000..7d753e1 --- /dev/null +++ b/src/out/data_land.rs @@ -0,0 +1,98 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct DataLand { + x: i32, + z: i32, + offset: i32, + length: i32, + data: Vec, +} + +impl DataLand { + pub fn new( + x: i32, + z: i32, + offset: i32, + length: i32, + data: Vec, + ) -> DataLand { + return DataLand { + x, + z, + offset, + length, + data, + } + } +} + +impl MessageEncoder for DataLand { + fn id(&self) -> i32 { + return ServerInternalProt::DATA_LAND as i32; + } + + fn length(&self) -> i32 { + return -2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.x); + buf.p1(self.z); + buf.p2(self.offset); + buf.p2(self.length); + buf.pdata(&self.data, 0, self.data.len()); + } + + fn test(&self) -> usize { + return 6 + self.data.len(); + } +} + +// ---- + +pub struct DataLandDone { + x: i32, + z: i32, +} + +impl DataLandDone { + pub fn new( + x: i32, + z: i32, + ) -> DataLandDone { + return DataLandDone { + x, + z, + } + } +} + +impl MessageEncoder for DataLandDone { + fn id(&self) -> i32 { + return ServerInternalProt::DATA_LAND_DONE as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.x); + buf.p1(self.z); + } + + fn test(&self) -> usize { + return 2; + } +} diff --git a/src/out/data_loc.rs b/src/out/data_loc.rs new file mode 100644 index 0000000..bfe013f --- /dev/null +++ b/src/out/data_loc.rs @@ -0,0 +1,98 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct DataLoc { + x: i32, + z: i32, + offset: i32, + length: i32, + data: Vec, +} + +impl DataLoc { + pub fn new( + x: i32, + z: i32, + offset: i32, + length: i32, + data: Vec, + ) -> DataLoc { + return DataLoc { + x, + z, + offset, + length, + data, + } + } +} + +impl MessageEncoder for DataLoc { + fn id(&self) -> i32 { + return ServerInternalProt::DATA_LOC as i32; + } + + fn length(&self) -> i32 { + return -2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.x); + buf.p1(self.z); + buf.p2(self.offset); + buf.p2(self.length); + buf.pdata(&self.data, 0, self.data.len()); + } + + fn test(&self) -> usize { + return 6 + self.data.len(); + } +} + +// ---- + +pub struct DataLocDone { + x: i32, + z: i32, +} + +impl DataLocDone { + pub fn new( + x: i32, + z: i32, + ) -> DataLocDone { + return DataLocDone { + x, + z, + } + } +} + +impl MessageEncoder for DataLocDone { + fn id(&self) -> i32 { + return ServerInternalProt::DATA_LOC_DONE as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.x); + buf.p1(self.z); + } + + fn test(&self) -> usize { + return 2; + } +} diff --git a/src/out/enable_tracking.rs b/src/out/enable_tracking.rs new file mode 100644 index 0000000..cfd15d7 --- /dev/null +++ b/src/out/enable_tracking.rs @@ -0,0 +1,32 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct EnableTracking {} + +impl EnableTracking { + pub fn new() -> EnableTracking { + return EnableTracking {} + } +} + +impl MessageEncoder for EnableTracking { + fn id(&self) -> i32 { + return ServerInternalProt::ENABLE_TRACKING as i32; + } + + fn length(&self) -> i32 { + return 0; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, _: &mut Packet) {} + + fn test(&self) -> usize { + return 0; + } +} \ No newline at end of file diff --git a/src/out/finish_tracking.rs b/src/out/finish_tracking.rs new file mode 100644 index 0000000..c483e80 --- /dev/null +++ b/src/out/finish_tracking.rs @@ -0,0 +1,32 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct FinishTracking {} + +impl FinishTracking { + pub fn new() -> FinishTracking { + return FinishTracking {} + } +} + +impl MessageEncoder for FinishTracking { + fn id(&self) -> i32 { + return ServerInternalProt::FINISH_TRACKING as i32; + } + + fn length(&self) -> i32 { + return 0; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, _: &mut Packet) {} + + fn test(&self) -> usize { + return 0; + } +} \ No newline at end of file diff --git a/src/out/hint_arrow.rs b/src/out/hint_arrow.rs new file mode 100644 index 0000000..5dbc217 --- /dev/null +++ b/src/out/hint_arrow.rs @@ -0,0 +1,85 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct HintArrow { + arrow: i32, + nid: i32, + pid: i32, + x: i32, + z: i32, + y: i32, +} + +impl HintArrow { + pub fn new( + arrow: i32, + nid: i32, + pid: i32, + x: i32, + z: i32, + y: i32, + ) -> HintArrow { + return HintArrow { + arrow, + nid, + pid, + x, + z, + y, + } + } +} + +impl MessageEncoder for HintArrow { + fn id(&self) -> i32 { + return ServerInternalProt::HINT_ARROW as i32; + } + + fn length(&self) -> i32 { + return 6; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; // todo: what should priority be? + } + + fn encode(&self, buf: &mut Packet) { + match self.arrow { + 1 => { + buf.p1(self.arrow); + buf.p2(self.nid); + buf.p2(0); + buf.p1(0); + }, + 2..=6 => { + // 2 - 64, 64 offset - centered + // 3 - 0, 64 offset - far left + // 4 - 128, 64 offset - far right + // 5 - 64, 0 offset - bottom left + // 6 - 64, 128 offset - top left + buf.p1(self.arrow); + buf.p2(self.x); + buf.p2(self.z); + buf.p1(self.y); + }, + 10 => { + buf.p1(self.arrow); + buf.p2(self.pid); + buf.p2(0); + buf.p1(0); + }, + _ => { + buf.p1(-1); + buf.p2(0); + buf.p2(0); + buf.p1(0); + }, + } + } + + fn test(&self) -> usize { + return 6; + } +} \ No newline at end of file diff --git a/src/out/if_close.rs b/src/out/if_close.rs new file mode 100644 index 0000000..8649cf9 --- /dev/null +++ b/src/out/if_close.rs @@ -0,0 +1,32 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfClose {} + +impl IfClose { + pub fn new() -> IfClose { + return IfClose {} + } +} + +impl MessageEncoder for IfClose { + fn id(&self) -> i32 { + return ServerInternalProt::IF_CLOSE as i32; + } + + fn length(&self) -> i32 { + return 0; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, _: &mut Packet) {} + + fn test(&self) -> usize { + return 0; + } +} \ No newline at end of file diff --git a/src/out/if_openchat.rs b/src/out/if_openchat.rs new file mode 100644 index 0000000..60c6b11 --- /dev/null +++ b/src/out/if_openchat.rs @@ -0,0 +1,38 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfOpenChat { + component: i32, +} + +impl IfOpenChat { + pub fn new(component:i32) -> IfOpenChat { + return IfOpenChat { + component, + } + } +} + +impl MessageEncoder for IfOpenChat { + fn id(&self) -> i32 { + return ServerInternalProt::IF_OPENCHAT as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/if_openmainside.rs b/src/out/if_openmainside.rs new file mode 100644 index 0000000..559a531 --- /dev/null +++ b/src/out/if_openmainside.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfOpenMainSide { + main: i32, + side: i32, +} + +impl IfOpenMainSide { + pub fn new( + main: i32, + side: i32, + ) -> IfOpenMainSide { + return IfOpenMainSide { + main, + side, + } + } +} + +impl MessageEncoder for IfOpenMainSide { + fn id(&self) -> i32 { + return ServerInternalProt::IF_OPENMAIN_SIDE as i32; + } + + fn length(&self) -> i32 { + return 4; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.main); + buf.p2(self.side); + } + + fn test(&self) -> usize { + return 4; + } +} \ No newline at end of file diff --git a/src/out/if_setanim.rs b/src/out/if_setanim.rs new file mode 100644 index 0000000..9405196 --- /dev/null +++ b/src/out/if_setanim.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetAnim { + component: i32, + seq: i32, +} + +impl IfSetAnim { + pub fn new( + component: i32, + seq: i32, + ) -> IfSetAnim { + return IfSetAnim { + component, + seq, + } + } +} + +impl MessageEncoder for IfSetAnim { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETANIM as i32; + } + + fn length(&self) -> i32 { + return 4; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + buf.p2(self.seq); + } + + fn test(&self) -> usize { + return 4; + } +} \ No newline at end of file diff --git a/src/out/if_setcolour.rs b/src/out/if_setcolour.rs new file mode 100644 index 0000000..a4fb89e --- /dev/null +++ b/src/out/if_setcolour.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetColour { + component: i32, + colour: i32, +} + +impl IfSetColour { + pub fn new( + component: i32, + colour: i32, + ) -> IfSetColour { + return IfSetColour { + component, + colour, + } + } +} + +impl MessageEncoder for IfSetColour { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETCOLOUR as i32; + } + + fn length(&self) -> i32 { + return 4; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + buf.p2(self.colour); + } + + fn test(&self) -> usize { + return 4; + } +} \ No newline at end of file diff --git a/src/out/if_sethide.rs b/src/out/if_sethide.rs new file mode 100644 index 0000000..b5960c0 --- /dev/null +++ b/src/out/if_sethide.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetHide { + component: i32, + hidden: bool, +} + +impl IfSetHide { + pub fn new( + component: i32, + hidden: bool, + ) -> IfSetHide { + return IfSetHide { + component, + hidden, + } + } +} + +impl MessageEncoder for IfSetHide { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETHIDE as i32; + } + + fn length(&self) -> i32 { + return 3; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + buf.p1(if self.hidden { 1 } else { 0 }); + } + + fn test(&self) -> usize { + return 3; + } +} \ No newline at end of file diff --git a/src/out/if_setmodel.rs b/src/out/if_setmodel.rs new file mode 100644 index 0000000..1b208b8 --- /dev/null +++ b/src/out/if_setmodel.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetModel { + component: i32, + model: i32, +} + +impl IfSetModel { + pub fn new( + component: i32, + model: i32, + ) -> IfSetModel { + return IfSetModel { + component, + model, + } + } +} + +impl MessageEncoder for IfSetModel { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETMODEL as i32; + } + + fn length(&self) -> i32 { + return 4; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + buf.p2(self.model); + } + + fn test(&self) -> usize { + return 4; + } +} \ No newline at end of file diff --git a/src/out/if_setnpchead.rs b/src/out/if_setnpchead.rs new file mode 100644 index 0000000..102e3e9 --- /dev/null +++ b/src/out/if_setnpchead.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetNpcHead { + component: i32, + npc: i32, +} + +impl IfSetNpcHead { + pub fn new( + component: i32, + npc: i32, + ) -> IfSetNpcHead { + return IfSetNpcHead { + component, + npc, + } + } +} + +impl MessageEncoder for IfSetNpcHead { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETNPCHEAD as i32; + } + + fn length(&self) -> i32 { + return 4; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + buf.p2(self.npc); + } + + fn test(&self) -> usize { + return 4; + } +} \ No newline at end of file diff --git a/src/out/if_setobject.rs b/src/out/if_setobject.rs new file mode 100644 index 0000000..3470e9e --- /dev/null +++ b/src/out/if_setobject.rs @@ -0,0 +1,48 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetObject { + component: i32, + obj: i32, + scale: i32, +} + +impl IfSetObject { + pub fn new( + component: i32, + obj: i32, + scale: i32, + ) -> IfSetObject { + return IfSetObject { + component, + obj, + scale, + } + } +} + +impl MessageEncoder for IfSetObject { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETOBJECT as i32; + } + + fn length(&self) -> i32 { + return 6; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + buf.p2(self.obj); + buf.p2(self.scale); + } + + fn test(&self) -> usize { + return 6; + } +} \ No newline at end of file diff --git a/src/out/if_setplayerhead.rs b/src/out/if_setplayerhead.rs new file mode 100644 index 0000000..d821863 --- /dev/null +++ b/src/out/if_setplayerhead.rs @@ -0,0 +1,40 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetPlayerHead { + component: i32, +} + +impl IfSetPlayerHead { + pub fn new( + component: i32, + ) -> IfSetPlayerHead { + return IfSetPlayerHead { + component, + } + } +} + +impl MessageEncoder for IfSetPlayerHead { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETPLAYERHEAD as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/if_setposition.rs b/src/out/if_setposition.rs new file mode 100644 index 0000000..5fb7b3a --- /dev/null +++ b/src/out/if_setposition.rs @@ -0,0 +1,48 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetPosition { + component: i32, + x: i32, + y: i32, +} + +impl IfSetPosition { + pub fn new( + component: i32, + x: i32, + y: i32, + ) -> IfSetPosition { + return IfSetPosition { + component, + x, + y, + } + } +} + +impl MessageEncoder for IfSetPosition { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETPOSITION as i32; + } + + fn length(&self) -> i32 { + return 6; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + buf.p2(self.x); + buf.p2(self.y); + } + + fn test(&self) -> usize { + return 6; + } +} \ No newline at end of file diff --git a/src/out/if_setrecol.rs b/src/out/if_setrecol.rs new file mode 100644 index 0000000..5eec1b9 --- /dev/null +++ b/src/out/if_setrecol.rs @@ -0,0 +1,48 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetRecol { + component: i32, + src: i32, + dst: i32, +} + +impl IfSetRecol { + pub fn new( + component: i32, + src: i32, + dst: i32, + ) -> IfSetRecol { + return IfSetRecol { + component, + src, + dst, + } + } +} + +impl MessageEncoder for IfSetRecol { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETRECOL as i32; + } + + fn length(&self) -> i32 { + return 6; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + buf.p2(self.src); + buf.p2(self.dst); + } + + fn test(&self) -> usize { + return 6; + } +} \ No newline at end of file diff --git a/src/out/if_settab.rs b/src/out/if_settab.rs new file mode 100644 index 0000000..24f918a --- /dev/null +++ b/src/out/if_settab.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetTab { + component: i32, + tab: i32, +} + +impl IfSetTab { + pub fn new( + component: i32, + tab: i32, + ) -> IfSetTab { + return IfSetTab { + component, + tab, + } + } +} + +impl MessageEncoder for IfSetTab { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETTAB as i32; + } + + fn length(&self) -> i32 { + return 3; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + buf.p1(self.tab); + } + + fn test(&self) -> usize { + return 3; + } +} \ No newline at end of file diff --git a/src/out/if_settabactive.rs b/src/out/if_settabactive.rs new file mode 100644 index 0000000..0f17219 --- /dev/null +++ b/src/out/if_settabactive.rs @@ -0,0 +1,40 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetTabActive { + tab: i32, +} + +impl IfSetTabActive { + pub fn new( + tab: i32, + ) -> IfSetTabActive { + return IfSetTabActive { + tab, + } + } +} + +impl MessageEncoder for IfSetTabActive { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETTAB_ACTIVE as i32; + } + + fn length(&self) -> i32 { + return 1; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.tab); + } + + fn test(&self) -> usize { + return 1; + } +} \ No newline at end of file diff --git a/src/out/if_settext.rs b/src/out/if_settext.rs new file mode 100644 index 0000000..e00bd83 --- /dev/null +++ b/src/out/if_settext.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct IfSetText { + component: i32, + text: String, +} + +impl IfSetText { + pub fn new( + component: i32, + text: String, + ) -> IfSetText { + return IfSetText { + component, + text, + } + } +} + +impl MessageEncoder for IfSetText { + fn id(&self) -> i32 { + return ServerInternalProt::IF_SETTEXT as i32; + } + + fn length(&self) -> i32 { + return -2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + buf.pjstr(&self.text, 10); + } + + fn test(&self) -> usize { + return 3 + self.text.len(); + } +} \ No newline at end of file diff --git a/src/out/last_login_info.rs b/src/out/last_login_info.rs new file mode 100644 index 0000000..966dcaf --- /dev/null +++ b/src/out/last_login_info.rs @@ -0,0 +1,52 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct LastLoginInfo { + last_ip: i32, + days_since_login: i32, + days_since_recovery: i32, + messages: i32, +} + +impl LastLoginInfo { + pub fn new( + last_ip: i32, + days_since_login: i32, + days_since_recovery: i32, + messages: i32, + ) -> LastLoginInfo { + return LastLoginInfo { + last_ip, + days_since_login, + days_since_recovery, + messages, + } + } +} + +impl MessageEncoder for LastLoginInfo { + fn id(&self) -> i32 { + return ServerInternalProt::LAST_LOGIN_INFO as i32; + } + + fn length(&self) -> i32 { + return 9; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p4(self.last_ip); + buf.p2(self.days_since_login); + buf.p1(self.days_since_recovery); + buf.p2(self.messages); + } + + fn test(&self) -> usize { + return 9; + } +} \ No newline at end of file diff --git a/src/out/loc_addchange.rs b/src/out/loc_addchange.rs new file mode 100644 index 0000000..acf269e --- /dev/null +++ b/src/out/loc_addchange.rs @@ -0,0 +1,51 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct LocAddChange { + coord: i32, + loc: i32, + shape: i32, + angle: i32, +} + +impl LocAddChange { + pub fn new( + coord: i32, + loc: i32, + shape: i32, + angle: i32, + ) -> LocAddChange { + return LocAddChange { + coord, + loc, + shape, + angle, + } + } +} + +impl MessageEncoder for LocAddChange { + fn id(&self) -> i32 { + return ServerInternalProt::LOC_ADD_CHANGE as i32; + } + + fn length(&self) -> i32 { + return 4; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.coord); + buf.p1((self.shape << 2) | (self.angle & 0x3)); + buf.p2(self.loc); + } + + fn test(&self) -> usize { + return 4; + } +} \ No newline at end of file diff --git a/src/out/loc_anim.rs b/src/out/loc_anim.rs new file mode 100644 index 0000000..7478f05 --- /dev/null +++ b/src/out/loc_anim.rs @@ -0,0 +1,51 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct LocAnim { + coord: i32, + shape: i32, + angle: i32, + seq: i32, +} + +impl LocAnim { + pub fn new( + coord: i32, + shape: i32, + angle: i32, + seq: i32, + ) -> LocAnim { + return LocAnim { + coord, + shape, + angle, + seq, + } + } +} + +impl MessageEncoder for LocAnim { + fn id(&self) -> i32 { + return ServerInternalProt::LOC_ANIM as i32; + } + + fn length(&self) -> i32 { + return 4; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.coord); + buf.p1((self.shape << 2) | (self.angle & 0x3)); + buf.p2(self.seq); + } + + fn test(&self) -> usize { + return 4; + } +} \ No newline at end of file diff --git a/src/out/loc_del.rs b/src/out/loc_del.rs new file mode 100644 index 0000000..03c27be --- /dev/null +++ b/src/out/loc_del.rs @@ -0,0 +1,47 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct LocDel { + coord: i32, + shape: i32, + angle: i32, +} + +impl LocDel { + pub fn new( + coord: i32, + shape: i32, + angle: i32, + ) -> LocDel { + return LocDel { + coord, + shape, + angle, + } + } +} + +impl MessageEncoder for LocDel { + fn id(&self) -> i32 { + return ServerInternalProt::LOC_DEL as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.coord); + buf.p1((self.shape << 2) | (self.angle & 0x3)); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/loc_merge.rs b/src/out/loc_merge.rs new file mode 100644 index 0000000..3448f6c --- /dev/null +++ b/src/out/loc_merge.rs @@ -0,0 +1,85 @@ +use crate::coord::CoordGrid; +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct LocMerge { + coord: i32, + src_x: i32, + src_z: i32, + shape: i32, + angle: i32, + loc: i32, + start: i32, + end: i32, + pid: i32, + east: i32, + south: i32, + west: i32, + north: i32, +} + +impl LocMerge { + pub fn new( + src_x: i32, + src_z: i32, + shape: i32, + angle: i32, + loc: i32, + start: i32, + end: i32, + pid: i32, + east: i32, + south: i32, + west: i32, + north: i32, + ) -> LocMerge { + return LocMerge { + coord: CoordGrid::pack_zone_coord(src_x as u16, src_z as u16) as i32, + src_x, + src_z, + shape, + angle, + loc, + start, + end, + pid, + east, + south, + west, + north, + } + } +} + +impl MessageEncoder for LocMerge { + fn id(&self) -> i32 { + return ServerInternalProt::LOC_MERGE as i32; + } + + fn length(&self) -> i32 { + return 14; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.coord); + buf.p1((self.shape << 2) | (self.angle & 0x3)); + buf.p2(self.loc); + buf.p2(self.start); + buf.p2(self.end); + buf.p2(self.pid); + buf.p1(self.east - self.src_x); + buf.p1(self.south - self.src_z); + buf.p1(self.west - self.src_x); + buf.p1(self.north - self.src_z); + } + + fn test(&self) -> usize { + return 14; + } +} \ No newline at end of file diff --git a/src/out/logout.rs b/src/out/logout.rs new file mode 100644 index 0000000..90d0d7a --- /dev/null +++ b/src/out/logout.rs @@ -0,0 +1,32 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct Logout {} + +impl Logout { + pub fn new() -> Logout { + return Logout {} + } +} + +impl MessageEncoder for Logout { + fn id(&self) -> i32 { + return ServerInternalProt::LOGOUT as i32; + } + + fn length(&self) -> i32 { + return 0; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, _: &mut Packet) {} + + fn test(&self) -> usize { + return 0; + } +} \ No newline at end of file diff --git a/src/out/map_anim.rs b/src/out/map_anim.rs new file mode 100644 index 0000000..c4d459e --- /dev/null +++ b/src/out/map_anim.rs @@ -0,0 +1,52 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct MapAnim { + coord: i32, + spotanim: i32, + height: i32, + delay: i32, +} + +impl MapAnim { + pub fn new( + coord: i32, + spotanim: i32, + height: i32, + delay: i32, + ) -> MapAnim { + return MapAnim { + coord, + spotanim, + height, + delay, + } + } +} + +impl MessageEncoder for MapAnim { + fn id(&self) -> i32 { + return ServerInternalProt::MAP_ANIM as i32; + } + + fn length(&self) -> i32 { + return 6; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.coord); + buf.p2(self.spotanim); + buf.p1(self.height); + buf.p2(self.delay); + } + + fn test(&self) -> usize { + return 6; + } +} \ No newline at end of file diff --git a/src/out/map_projanim.rs b/src/out/map_projanim.rs new file mode 100644 index 0000000..8af0dee --- /dev/null +++ b/src/out/map_projanim.rs @@ -0,0 +1,86 @@ +use crate::coord::CoordGrid; +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct MapProjAnim { + coord: i32, + src_x: i32, + src_z: i32, + dst_x: i32, + dst_z: i32, + target: i32, + spotanim: i32, + src_height: i32, + dst_height: i32, + start: i32, + end: i32, + peak: i32, + arc: i32, +} + +impl MapProjAnim { + pub fn new( + src_x: i32, + src_z: i32, + dst_x: i32, + dst_z: i32, + target: i32, + spotanim: i32, + src_height: i32, + dst_height: i32, + start: i32, + end: i32, + peak: i32, + arc: i32, + ) -> MapProjAnim { + return MapProjAnim { + coord: CoordGrid::pack_zone_coord(src_x as u16, src_z as u16) as i32, + src_x, + src_z, + dst_x, + dst_z, + target, + spotanim, + src_height, + dst_height, + start, + end, + peak, + arc, + } + } +} + +impl MessageEncoder for MapProjAnim { + fn id(&self) -> i32 { + return ServerInternalProt::MAP_PROJANIM as i32; + } + + fn length(&self) -> i32 { + return 15; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.coord); + buf.p1(self.dst_x - self.src_x); + buf.p1(self.dst_z - self.src_z); + buf.p2(self.target); // 0: coord, > 0: npc, < 0: player + buf.p2(self.spotanim); + buf.p1(self.src_height); + buf.p1(self.dst_height); + buf.p2(self.start); + buf.p2(self.end); + buf.p1(self.peak); + buf.p1(self.arc); + } + + fn test(&self) -> usize { + return 15; + } +} \ No newline at end of file diff --git a/src/out/message_private.rs b/src/out/message_private.rs new file mode 100644 index 0000000..25315f8 --- /dev/null +++ b/src/out/message_private.rs @@ -0,0 +1,58 @@ +use crate::message::MessageEncoder; +use crate::pack::WordPack; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct MessagePrivateOut { + from: i64, + id: i32, + staff_mod_level: i32, + msg: String, +} + +impl MessagePrivateOut { + pub fn new( + from: i64, + id: i32, + staff_mod_level: i32, + msg: String, + ) -> MessagePrivateOut { + return MessagePrivateOut { + from, + id, + staff_mod_level, + msg, + } + } +} + +impl MessageEncoder for MessagePrivateOut { + fn id(&self) -> i32 { + return ServerInternalProt::MESSAGE_PRIVATE as i32 + } + + fn length(&self) -> i32 { + return -1; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + let mut staff_mod_level = self.staff_mod_level; + if staff_mod_level > 0 { + staff_mod_level += 1; + } + + buf.p8(self.from); + buf.p4(self.id); + buf.p1(staff_mod_level); + unsafe { WordPack::pack(buf, self.msg.clone()); } + } + + fn test(&self) -> usize { + return 14 + self.msg.len(); + } +} \ No newline at end of file diff --git a/src/out/midi_jingle.rs b/src/out/midi_jingle.rs new file mode 100644 index 0000000..1b2f647 --- /dev/null +++ b/src/out/midi_jingle.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct MidiJingle { + delay: i32, + data: Vec, +} + +impl MidiJingle { + pub fn new( + delay: i32, + data: Vec, + ) -> MidiJingle { + return MidiJingle { + delay, + data, + } + } +} + +impl MessageEncoder for MidiJingle { + fn id(&self) -> i32 { + return ServerInternalProt::MIDI_JINGLE as i32; + } + + fn length(&self) -> i32 { + return -2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.delay); + buf.pdata(&self.data, 0, self.data.len()); + } + + fn test(&self) -> usize { + return 6 + self.data.len(); + } +} \ No newline at end of file diff --git a/src/out/midi_song.rs b/src/out/midi_song.rs new file mode 100644 index 0000000..379f598 --- /dev/null +++ b/src/out/midi_song.rs @@ -0,0 +1,48 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct MidiSong { + name: String, + crc: i32, + length: i32, +} + +impl MidiSong { + pub fn new( + name: String, + crc: i32, + length: i32, + ) -> MidiSong { + return MidiSong { + name, + crc, + length, + } + } +} + +impl MessageEncoder for MidiSong { + fn id(&self) -> i32 { + return ServerInternalProt::MIDI_SONG as i32; + } + + fn length(&self) -> i32 { + return -1; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.pjstr(&self.name, 10); + buf.p4(self.crc); + buf.p4(self.length); + } + + fn test(&self) -> usize { + return 9 + self.name.len(); + } +} \ No newline at end of file diff --git a/src/out/mod.rs b/src/out/mod.rs index 62b23c4..b6cdd78 100644 --- a/src/out/mod.rs +++ b/src/out/mod.rs @@ -2,4 +2,68 @@ pub mod if_openmain; pub mod if_openside; pub mod message_game; pub mod player_info; -pub mod npc_info; \ No newline at end of file +pub mod npc_info; +pub mod cam_lookat; +pub mod cam_moveto; +pub mod cam_reset; +pub mod cam_shake; +pub mod chat_filter_settings; +pub mod data_land; +pub mod data_loc; +pub mod enable_tracking; +pub mod finish_tracking; +pub mod hint_arrow; +pub mod if_close; +pub mod if_openchat; +pub mod if_openmainside; +pub mod if_settab; +pub mod if_setanim; +pub mod if_setcolour; +pub mod if_sethide; +pub mod if_setmodel; +pub mod if_setnpchead; +pub mod if_setobject; +pub mod if_setplayerhead; +pub mod if_setposition; +pub mod if_setrecol; +pub mod if_settext; +pub mod if_settabactive; +pub mod last_login_info; +pub mod loc_addchange; +pub mod loc_anim; +pub mod loc_del; +pub mod loc_merge; +pub mod logout; +pub mod map_anim; +pub mod map_projanim; +pub mod message_private; +pub mod midi_jingle; +pub mod midi_song; +pub mod obj_add; +pub mod obj_count; +pub mod obj_del; +pub mod obj_reveal; +pub mod count_dialog; +pub mod rebuild_normal; +pub mod reset_anims; +pub mod reset_clientvarcache; +pub mod set_multiway; +pub mod synth_sound; +pub mod tut_flash; +pub mod tut_open; +pub mod unset_map_flag; +pub mod update_friendlist; +pub mod update_ignorelist; +pub mod update_inv_stop_transmit; +pub mod update_runenergy; +pub mod update_runweight; +pub mod update_reboot_timer; +pub mod update_stat; +pub mod update_pid; +pub mod update_zone_full_follows; +pub mod update_zone_partial_follows; +pub mod update_zone_partial_enclosed; +pub mod varp_large; +pub mod varp_small; +pub mod update_inv_full; +pub mod update_inv_partial; \ No newline at end of file diff --git a/src/out/obj_add.rs b/src/out/obj_add.rs new file mode 100644 index 0000000..1863ed2 --- /dev/null +++ b/src/out/obj_add.rs @@ -0,0 +1,48 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct ObjAdd { + coord: i32, + obj: i32, + count: i32, +} + +impl ObjAdd { + pub fn new( + coord: i32, + obj: i32, + count: i32, + ) -> ObjAdd { + return ObjAdd { + coord, + obj, + count, + } + } +} + +impl MessageEncoder for ObjAdd { + fn id(&self) -> i32 { + return ServerInternalProt::OBJ_ADD as i32; + } + + fn length(&self) -> i32 { + return 5; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.coord); + buf.p2(self.obj); + buf.p2(self.count.min(65535)); + } + + fn test(&self) -> usize { + return 5; + } +} \ No newline at end of file diff --git a/src/out/obj_count.rs b/src/out/obj_count.rs new file mode 100644 index 0000000..83aa7fb --- /dev/null +++ b/src/out/obj_count.rs @@ -0,0 +1,52 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct ObjCount { + coord: i32, + obj: i32, + old_count: i32, + new_count: i32, +} + +impl ObjCount { + pub fn new( + coord: i32, + obj: i32, + old_count: i32, + new_count: i32, + ) -> ObjCount { + return ObjCount { + coord, + obj, + old_count, + new_count, + } + } +} + +impl MessageEncoder for ObjCount { + fn id(&self) -> i32 { + return ServerInternalProt::OBJ_COUNT as i32; + } + + fn length(&self) -> i32 { + return 7; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.coord); + buf.p2(self.obj); + buf.p2(self.old_count.min(65535)); + buf.p2(self.new_count.min(65535)); + } + + fn test(&self) -> usize { + return 7; + } +} \ No newline at end of file diff --git a/src/out/obj_del.rs b/src/out/obj_del.rs new file mode 100644 index 0000000..54d588a --- /dev/null +++ b/src/out/obj_del.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct ObjDel { + coord: i32, + obj: i32, +} + +impl ObjDel { + pub fn new( + coord: i32, + obj: i32, + ) -> ObjDel { + return ObjDel { + coord, + obj, + } + } +} + +impl MessageEncoder for ObjDel { + fn id(&self) -> i32 { + return ServerInternalProt::OBJ_DEL as i32; + } + + fn length(&self) -> i32 { + return 3; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.coord); + buf.p2(self.obj); + } + + fn test(&self) -> usize { + return 3; + } +} \ No newline at end of file diff --git a/src/out/obj_reveal.rs b/src/out/obj_reveal.rs new file mode 100644 index 0000000..1586aa4 --- /dev/null +++ b/src/out/obj_reveal.rs @@ -0,0 +1,52 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct ObjReveal { + coord: i32, + obj: i32, + count: i32, + receiver: i32, +} + +impl ObjReveal { + pub fn new( + coord: i32, + obj: i32, + count: i32, + receiver: i32, + ) -> ObjReveal { + return ObjReveal { + coord, + obj, + count, + receiver, + } + } +} + +impl MessageEncoder for ObjReveal { + fn id(&self) -> i32 { + return ServerInternalProt::OBJ_REVEAL as i32; + } + + fn length(&self) -> i32 { + return 7; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.coord); + buf.p2(self.obj); + buf.p2(self.count.min(65535)); + buf.p2(self.receiver); + } + + fn test(&self) -> usize { + return 7; + } +} \ No newline at end of file diff --git a/src/out/rebuild_normal.rs b/src/out/rebuild_normal.rs new file mode 100644 index 0000000..b43d9b6 --- /dev/null +++ b/src/out/rebuild_normal.rs @@ -0,0 +1,67 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct RebuildNormal { + x: i32, + z: i32, + squares: Vec, + maps: Vec, + locs: Vec, +} + +impl RebuildNormal { + pub fn new( + x: i32, + z: i32, + squares: Vec, + maps: Vec, + locs: Vec, + ) -> RebuildNormal { + return RebuildNormal { + x, + z, + squares, + maps, + locs, + } + } +} + +impl MessageEncoder for RebuildNormal { + fn id(&self) -> i32 { + return ServerInternalProt::REBUILD_NORMAL as i32; + } + + fn length(&self) -> i32 { + return -2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.x); + buf.p2(self.z); + for index in 0..self.squares.len() { + let mapsquare: u16 = unsafe { *self.squares.as_ptr().add(index) }; + buf.p1(((mapsquare >> 8) & 0xff) as i32); + buf.p1((mapsquare & 0xff) as i32); + buf.p4(unsafe { *self.maps.as_ptr().add(index) }); + buf.p4(unsafe { *self.locs.as_ptr().add(index) }); + } + // for &packed in self.squares.iter() { + // // buf.p1(((packed >> 72) & 0xff) as i32); + // // buf.p1(((packed >> 64) & 0xff) as i32); + // // buf.p4(((packed >> 32) & 0xffffffff) as i32); + // // buf.p4((packed & 0xffffffff) as i32); + // // (50n << 72n) + (50n << 64n) + (BigInt.asUintN(32, -2147483648n) << 32n) + 2147483647n + // } + } + + fn test(&self) -> usize { + return 2 + 2 + self.squares.len() * (1 + 1 + 4 + 4); + } +} \ No newline at end of file diff --git a/src/out/reset_anims.rs b/src/out/reset_anims.rs new file mode 100644 index 0000000..2227ea8 --- /dev/null +++ b/src/out/reset_anims.rs @@ -0,0 +1,32 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct ResetAnims {} + +impl ResetAnims { + pub fn new() -> ResetAnims { + return ResetAnims {} + } +} + +impl MessageEncoder for ResetAnims { + fn id(&self) -> i32 { + return ServerInternalProt::RESET_ANIMS as i32; + } + + fn length(&self) -> i32 { + return 0; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; // todo: what should priority be? + } + + fn encode(&self, _: &mut Packet) {} + + fn test(&self) -> usize { + return 0; + } +} \ No newline at end of file diff --git a/src/out/reset_clientvarcache.rs b/src/out/reset_clientvarcache.rs new file mode 100644 index 0000000..9d8f0d0 --- /dev/null +++ b/src/out/reset_clientvarcache.rs @@ -0,0 +1,32 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct ResetClientVarCache {} + +impl ResetClientVarCache { + pub fn new() -> ResetClientVarCache { + return ResetClientVarCache {} + } +} + +impl MessageEncoder for ResetClientVarCache { + fn id(&self) -> i32 { + return ServerInternalProt::RESET_CLIENT_VARCACHE as i32; + } + + fn length(&self) -> i32 { + return 0; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, _: &mut Packet) {} + + fn test(&self) -> usize { + return 0; + } +} \ No newline at end of file diff --git a/src/out/set_multiway.rs b/src/out/set_multiway.rs new file mode 100644 index 0000000..510bf94 --- /dev/null +++ b/src/out/set_multiway.rs @@ -0,0 +1,38 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct SetMultiway { + hidden: bool, +} + +impl SetMultiway { + pub fn new(hidden: bool) -> SetMultiway { + return SetMultiway { + hidden, + } + } +} + +impl MessageEncoder for SetMultiway { + fn id(&self) -> i32 { + return ServerInternalProt::SET_MULTIWAY as i32; + } + + fn length(&self) -> i32 { + return 1; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(if self.hidden { 1 } else { 0 }); + } + + fn test(&self) -> usize { + return 1; + } +} \ No newline at end of file diff --git a/src/out/synth_sound.rs b/src/out/synth_sound.rs new file mode 100644 index 0000000..223dcce --- /dev/null +++ b/src/out/synth_sound.rs @@ -0,0 +1,48 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct SynthSound { + synth: i32, + loops: i32, + delay: i32, +} + +impl SynthSound { + pub fn new( + synth: i32, + loops: i32, + delay: i32, + ) -> SynthSound { + return SynthSound { + synth, + loops, + delay, + } + } +} + +impl MessageEncoder for SynthSound { + fn id(&self) -> i32 { + return ServerInternalProt::SYNTH_SOUND as i32; + } + + fn length(&self) -> i32 { + return 5; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.synth); + buf.p1(self.loops); + buf.p2(self.delay); + } + + fn test(&self) -> usize { + return 5; + } +} \ No newline at end of file diff --git a/src/out/tut_flash.rs b/src/out/tut_flash.rs new file mode 100644 index 0000000..36fc337 --- /dev/null +++ b/src/out/tut_flash.rs @@ -0,0 +1,40 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct TutFlash { + tab: i32, +} + +impl TutFlash { + pub fn new( + tab: i32, + ) -> TutFlash { + return TutFlash { + tab, + } + } +} + +impl MessageEncoder for TutFlash { + fn id(&self) -> i32 { + return ServerInternalProt::TUT_FLASH as i32; + } + + fn length(&self) -> i32 { + return 1; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.tab); + } + + fn test(&self) -> usize { + return 1; + } +} \ No newline at end of file diff --git a/src/out/tut_open.rs b/src/out/tut_open.rs new file mode 100644 index 0000000..151b9f4 --- /dev/null +++ b/src/out/tut_open.rs @@ -0,0 +1,40 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct TutOpen { + component: i32, +} + +impl TutOpen { + pub fn new( + component: i32, + ) -> TutOpen { + return TutOpen { + component, + } + } +} + +impl MessageEncoder for TutOpen { + fn id(&self) -> i32 { + return ServerInternalProt::TUT_OPEN as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/unset_map_flag.rs b/src/out/unset_map_flag.rs new file mode 100644 index 0000000..6517fbe --- /dev/null +++ b/src/out/unset_map_flag.rs @@ -0,0 +1,32 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UnsetMapFlag {} + +impl UnsetMapFlag { + pub fn new() -> UnsetMapFlag { + return UnsetMapFlag {} + } +} + +impl MessageEncoder for UnsetMapFlag { + fn id(&self) -> i32 { + return ServerInternalProt::UNSET_MAP_FLAG as i32; + } + + fn length(&self) -> i32 { + return 0; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, _: &mut Packet) {} + + fn test(&self) -> usize { + return 0; + } +} \ No newline at end of file diff --git a/src/out/update_friendlist.rs b/src/out/update_friendlist.rs new file mode 100644 index 0000000..f18252c --- /dev/null +++ b/src/out/update_friendlist.rs @@ -0,0 +1,41 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateFriendList { + name: i64, + node: i32, +} + +impl UpdateFriendList { + pub fn new(name: i64, node: i32) -> UpdateFriendList { + return UpdateFriendList { + name, + node, + } + } +} + +impl MessageEncoder for UpdateFriendList { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_FRIENDLIST as i32; + } + + fn length(&self) -> i32 { + return 9; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p8(self.name); + buf.p1(self.node); + } + + fn test(&self) -> usize { + return 9; + } +} \ No newline at end of file diff --git a/src/out/update_ignorelist.rs b/src/out/update_ignorelist.rs new file mode 100644 index 0000000..770fa3e --- /dev/null +++ b/src/out/update_ignorelist.rs @@ -0,0 +1,40 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateIgnoreList { + names: Vec, +} + +impl UpdateIgnoreList { + pub fn new(names: Vec) -> UpdateIgnoreList { + return UpdateIgnoreList { + names, + } + } +} + +impl MessageEncoder for UpdateIgnoreList { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_IGNORELIST as i32; + } + + fn length(&self) -> i32 { + return -2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + for &name in self.names.iter() { + buf.p8(name); + } + } + + fn test(&self) -> usize { + return 8 * self.names.len(); + } +} \ No newline at end of file diff --git a/src/out/update_inv_full.rs b/src/out/update_inv_full.rs new file mode 100644 index 0000000..0033788 --- /dev/null +++ b/src/out/update_inv_full.rs @@ -0,0 +1,82 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateInvFull { + size: i32, + component: i32, + objs: Vec, +} + +impl UpdateInvFull { + pub fn new( + size: i32, + component: i32, + objs: Vec, + ) -> UpdateInvFull { + return UpdateInvFull { + size, + component, + objs, + } + } +} + +impl MessageEncoder for UpdateInvFull { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_INV_FULL as i32; + } + + fn length(&self) -> i32 { + return -2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + // todo: size should be the index of the last non-empty slot + buf.p2(self.component); + buf.p1(self.size); + for slot in 0..self.size { + let packed: i64 = self.objs[slot as usize]; + let obj: i32 = (packed >> 31) as i32; + if obj != -1 { + let count: i32 = (packed & 0x7fffffff) as i32; + buf.p2(obj + 1); + if count >= 0xff { + buf.p1(0xff); + buf.p4(count); + } else { + buf.p1(count); + } + } else { + buf.p2(0); + buf.p1(0); + } + } + } + + fn test(&self) -> usize { + let mut length: usize = 0; + length += 3; + for slot in 0..self.size { + let packed: i64 = self.objs[slot as usize]; + let obj: i32 = (packed >> 31) as i32; + if obj != -1 { + let count: i32 = (packed & 0x7fffffff) as i32; + length += 2; + if count >= 0xff { + length += 5; + } else { + length += 1; + } + } else { + length += 3; + } + } + return length; + } +} \ No newline at end of file diff --git a/src/out/update_inv_partial.rs b/src/out/update_inv_partial.rs new file mode 100644 index 0000000..5b51546 --- /dev/null +++ b/src/out/update_inv_partial.rs @@ -0,0 +1,82 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateInvPartial { + component: i32, + slots: Vec, + objs: Vec, +} + +impl UpdateInvPartial { + pub fn new( + component: i32, + slots: Vec, + objs: Vec, + ) -> UpdateInvPartial { + return UpdateInvPartial { + component, + slots, + objs, + } + } +} + +impl MessageEncoder for UpdateInvPartial { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_INV_PARTIAL as i32; + } + + fn length(&self) -> i32 { + return -2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + // todo: size should be the index of the last non-empty slot + buf.p2(self.component); + for &slot in self.slots.iter() { + let packed: i64 = self.objs[slot as usize]; + let obj: i32 = (packed >> 31) as i32; + buf.p1(slot); + if obj != -1 { + let count: i32 = (packed & 0x7fffffff) as i32; + buf.p2(obj + 1); + if count >= 0xff { + buf.p1(0xff); + buf.p4(count); + } else { + buf.p1(count); + } + } else { + buf.p2(0); + buf.p1(0); + } + } + } + + fn test(&self) -> usize { + let mut length: usize = 0; + length += 2; + for &slot in self.slots.iter() { + let packed: i64 = self.objs[slot as usize]; + let obj: i32 = (packed >> 31) as i32; + length += 1; + if obj != -1 { + let count: i32 = (packed & 0x7fffffff) as i32; + if count >= 0xff { + length += 5; + } else { + length += 1; + } + } else { + length += 3; + } + } + return length; + } +} \ No newline at end of file diff --git a/src/out/update_inv_stop_transmit.rs b/src/out/update_inv_stop_transmit.rs new file mode 100644 index 0000000..b73f180 --- /dev/null +++ b/src/out/update_inv_stop_transmit.rs @@ -0,0 +1,40 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateInvStopTransmit { + component: i32, +} + +impl UpdateInvStopTransmit { + pub fn new( + component: i32, + ) -> UpdateInvStopTransmit { + return UpdateInvStopTransmit { + component, + } + } +} + +impl MessageEncoder for UpdateInvStopTransmit { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_INV_STOP_TRANSMIT as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.component); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/update_pid.rs b/src/out/update_pid.rs new file mode 100644 index 0000000..faf5285 --- /dev/null +++ b/src/out/update_pid.rs @@ -0,0 +1,40 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdatePid { + pid: i32, +} + +impl UpdatePid { + pub fn new( + pid: i32, + ) -> UpdatePid { + return UpdatePid { + pid, + } + } +} + +impl MessageEncoder for UpdatePid { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_PID as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; // todo: what should priority be? + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.pid); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/update_reboot_timer.rs b/src/out/update_reboot_timer.rs new file mode 100644 index 0000000..e3d7733 --- /dev/null +++ b/src/out/update_reboot_timer.rs @@ -0,0 +1,40 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateRebootTimer { + ticks: i32, +} + +impl UpdateRebootTimer { + pub fn new( + ticks: i32, + ) -> UpdateRebootTimer { + return UpdateRebootTimer { + ticks, + } + } +} + +impl MessageEncoder for UpdateRebootTimer { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_REBOOT_TIMER as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; // todo: what should priority be? + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.ticks); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/update_runenergy.rs b/src/out/update_runenergy.rs new file mode 100644 index 0000000..4251702 --- /dev/null +++ b/src/out/update_runenergy.rs @@ -0,0 +1,40 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateRunEnergy { + energy: i32, +} + +impl UpdateRunEnergy { + pub fn new( + energy: i32, + ) -> UpdateRunEnergy { + return UpdateRunEnergy { + energy, + } + } +} + +impl MessageEncoder for UpdateRunEnergy { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_RUNENERGY as i32; + } + + fn length(&self) -> i32 { + return 1; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.energy / 100); + } + + fn test(&self) -> usize { + return 1; + } +} \ No newline at end of file diff --git a/src/out/update_runweight.rs b/src/out/update_runweight.rs new file mode 100644 index 0000000..56a8f20 --- /dev/null +++ b/src/out/update_runweight.rs @@ -0,0 +1,40 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateRunWeight { + kg: i32, +} + +impl UpdateRunWeight { + pub fn new( + kg: i32, + ) -> UpdateRunWeight { + return UpdateRunWeight { + kg, + } + } +} + +impl MessageEncoder for UpdateRunWeight { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_RUNWEIGHT as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.kg); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/update_stat.rs b/src/out/update_stat.rs new file mode 100644 index 0000000..1be53be --- /dev/null +++ b/src/out/update_stat.rs @@ -0,0 +1,48 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateStat { + stat: i32, + experience: i32, + level: i32, +} + +impl UpdateStat { + pub fn new( + stat: i32, + experience: i32, + level: i32, + ) -> UpdateStat { + return UpdateStat { + stat, + experience, + level, + } + } +} + +impl MessageEncoder for UpdateStat { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_STAT as i32; + } + + fn length(&self) -> i32 { + return 6; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Buffered; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1(self.stat); + buf.p4(self.experience / 10); + buf.p1(self.level); // not base level + } + + fn test(&self) -> usize { + return 6; + } +} \ No newline at end of file diff --git a/src/out/update_zone_full_follows.rs b/src/out/update_zone_full_follows.rs new file mode 100644 index 0000000..63fcc91 --- /dev/null +++ b/src/out/update_zone_full_follows.rs @@ -0,0 +1,51 @@ +use crate::coord::CoordGrid; +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateZoneFullFollows { + x: i32, + z: i32, + origin_x: i32, + origin_z: i32, +} + +impl UpdateZoneFullFollows { + pub fn new( + x: i32, + z: i32, + origin_x: i32, + origin_z: i32, + ) -> UpdateZoneFullFollows { + return UpdateZoneFullFollows { + x, + z, + origin_x, + origin_z, + } + } +} + +impl MessageEncoder for UpdateZoneFullFollows { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_ZONE_FULL_FOLLOWS as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1((self.x << 3) - CoordGrid::origin(self.origin_x as u16) as i32); + buf.p1((self.z << 3) - CoordGrid::origin(self.origin_z as u16) as i32); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/update_zone_partial_enclosed.rs b/src/out/update_zone_partial_enclosed.rs new file mode 100644 index 0000000..787490b --- /dev/null +++ b/src/out/update_zone_partial_enclosed.rs @@ -0,0 +1,55 @@ +use crate::coord::CoordGrid; +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateZonePartialEnclosed { + x: i32, + z: i32, + origin_x: i32, + origin_z: i32, + data: Vec, +} + +impl UpdateZonePartialEnclosed { + pub fn new( + x: i32, + z: i32, + origin_x: i32, + origin_z: i32, + data: Vec, + ) -> UpdateZonePartialEnclosed { + return UpdateZonePartialEnclosed { + x, + z, + origin_x, + origin_z, + data, + } + } +} + +impl MessageEncoder for UpdateZonePartialEnclosed { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_ZONE_PARTIAL_ENCLOSED as i32; + } + + fn length(&self) -> i32 { + return -2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1((self.x << 3) - CoordGrid::origin(self.origin_x as u16) as i32); + buf.p1((self.z << 3) - CoordGrid::origin(self.origin_z as u16) as i32); + buf.pdata(&self.data, 0, self.data.len()); + } + + fn test(&self) -> usize { + return 2 + self.data.len(); + } +} \ No newline at end of file diff --git a/src/out/update_zone_partial_follows.rs b/src/out/update_zone_partial_follows.rs new file mode 100644 index 0000000..37bdb7d --- /dev/null +++ b/src/out/update_zone_partial_follows.rs @@ -0,0 +1,51 @@ +use crate::coord::CoordGrid; +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct UpdateZonePartialFollows { + x: i32, + z: i32, + origin_x: i32, + origin_z: i32, +} + +impl UpdateZonePartialFollows { + pub fn new( + x: i32, + z: i32, + origin_x: i32, + origin_z: i32, + ) -> UpdateZonePartialFollows { + return UpdateZonePartialFollows { + x, + z, + origin_x, + origin_z, + } + } +} + +impl MessageEncoder for UpdateZonePartialFollows { + fn id(&self) -> i32 { + return ServerInternalProt::UPDATE_ZONE_PARTIAL_FOLLOWS as i32; + } + + fn length(&self) -> i32 { + return 2; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p1((self.x << 3) - CoordGrid::origin(self.origin_x as u16) as i32); + buf.p1((self.z << 3) - CoordGrid::origin(self.origin_z as u16) as i32); + } + + fn test(&self) -> usize { + return 2; + } +} \ No newline at end of file diff --git a/src/out/varp_large.rs b/src/out/varp_large.rs new file mode 100644 index 0000000..d9a25db --- /dev/null +++ b/src/out/varp_large.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct VarpLarge { + varp: i32, + value: i32, +} + +impl VarpLarge { + pub fn new( + varp: i32, + value: i32, + ) -> VarpLarge { + return VarpLarge { + varp, + value, + }; + } +} + +impl MessageEncoder for VarpLarge { + fn id(&self) -> i32 { + return ServerInternalProt::VARP_LARGE as i32; + } + + fn length(&self) -> i32 { + return 6; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.varp); + buf.p4(self.value); + } + + fn test(&self) -> usize { + return 6; + } +} \ No newline at end of file diff --git a/src/out/varp_small.rs b/src/out/varp_small.rs new file mode 100644 index 0000000..752ea17 --- /dev/null +++ b/src/out/varp_small.rs @@ -0,0 +1,44 @@ +use crate::message::MessageEncoder; +use crate::packet::Packet; +use crate::priority::ServerProtPriority; +use crate::prot::ServerInternalProt; + +pub struct VarpSmall { + varp: i32, + value: i32, +} + +impl VarpSmall { + pub fn new( + varp: i32, + value: i32, + ) -> VarpSmall { + return VarpSmall { + varp, + value, + }; + } +} + +impl MessageEncoder for VarpSmall { + fn id(&self) -> i32 { + return ServerInternalProt::VARP_SMALL as i32; + } + + fn length(&self) -> i32 { + return 3; + } + + fn priority(&self) -> ServerProtPriority { + return ServerProtPriority::Immediate; + } + + fn encode(&self, buf: &mut Packet) { + buf.p2(self.varp); + buf.p1(self.value); + } + + fn test(&self) -> usize { + return 3; + } +} \ No newline at end of file diff --git a/src/pack.rs b/src/pack.rs new file mode 100644 index 0000000..07605a0 --- /dev/null +++ b/src/pack.rs @@ -0,0 +1,119 @@ +use crate::packet::Packet; + +pub struct WordPack; + +impl WordPack { + const CHAR_LOOKUP: [char; 61] = [ + ' ', + 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r', 'd', 'l', 'u', 'm', + 'w', 'c', 'y', 'f', 'g', 'p', 'b', 'v', 'k', 'x', 'j', 'q', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-', + '&', '*', '\\', '\'', '@', '#', '+', '=', '£', '$', '%', '"', '[', ']' + ]; + + pub unsafe fn unpack(packet: &mut Packet, length: usize) -> String { + let mut char_buffer: Vec = Vec::with_capacity(80); + let mut pos: usize = 0; + let mut carry: i32 = -1; + + for _ in 0..length { + if pos >= 80 { + break; + } + + let data: u8 = packet.g1(); + let mut nibble: u8 = (data >> 4) & 0xf; + + if carry != -1 { + let index: i32 = ((carry << 4) + nibble as i32) - 195; + if index >= 0 && index < WordPack::CHAR_LOOKUP.len() as i32 { + *char_buffer.as_mut_ptr().add(pos) = *WordPack::CHAR_LOOKUP.as_ptr().add(index as usize); + pos += 1; + } + carry = -1; + } else if nibble < 13 { + *char_buffer.as_mut_ptr().add(pos) = *WordPack::CHAR_LOOKUP.as_ptr().add(nibble as usize); + pos += 1; + } else { + carry = nibble as i32; + } + + nibble = data & 0xf; + + if carry != -1 { + let index: i32 = ((carry << 4) + nibble as i32) - 195; + if index >= 0 && index < WordPack::CHAR_LOOKUP.len() as i32 { + *char_buffer.as_mut_ptr().add(pos) = *WordPack::CHAR_LOOKUP.as_ptr().add(index as usize); + pos += 1; + } + carry = -1; + } else if nibble < 13 { + *char_buffer.as_mut_ptr().add(pos) = *WordPack::CHAR_LOOKUP.as_ptr().add(nibble as usize); + pos += 1; + } else { + carry = nibble as i32; + } + } + + WordPack::sentence_case(&char_buffer.get_unchecked(..pos).iter().collect::()) + } + + pub unsafe fn pack(packet: &mut Packet, mut input: String) { + if input.len() > 80 { + input.truncate(80); + } + input = input.to_lowercase(); + let mut carry: i32 = -1; + + for c in input.chars() { + let mut index = 0; + for (j, &ch) in WordPack::CHAR_LOOKUP.iter().enumerate() { + if ch == c { + index = j as i32; + break; + } + } + + if index > 12 { + index += 195; + } + + if carry == -1 { + if index < 13 { + carry = index; + } else { + packet.p1(index); + } + } else if index < 13 { + packet.p1((carry << 4) + index); + carry = -1; + } else { + packet.p1((carry << 4) + (index >> 4)); + carry = index & 0xf; + } + } + + if carry != -1 { + packet.p1(carry << 4); + } + } + + pub fn sentence_case(input: &str) -> String { + let mut chars: Vec = input.to_lowercase().chars().collect(); + let mut punctuation: bool = true; + + for c in chars.iter_mut() { + if punctuation && c.is_ascii_lowercase() { + *c = c.to_ascii_uppercase(); + punctuation = false; + } + + if *c == '.' || *c == '!' { + punctuation = true; + } + } + + return chars.iter().collect(); + } +} \ No newline at end of file diff --git a/src/player.rs b/src/player.rs index f37acb8..77c421a 100644 --- a/src/player.rs +++ b/src/player.rs @@ -94,7 +94,7 @@ impl Player { graphic_height: -1, graphic_delay: -1, exact_move: None, - write_queue: VecDeque::new(), + write_queue: VecDeque::with_capacity(64), } } @@ -112,6 +112,20 @@ impl Player { }; } + #[inline] + pub fn write_zone_message(message: &dyn MessageEncoder, enclose: bool) -> Option { + return if enclose { + let mut buf: Packet = Packet::new(1 + message.test()); + buf.p1(message.id()); + message.encode(&mut buf); + Some(OutgoingPacket::new(Some(buf.data), message.id(), message.length())) + } else { + let mut buf: Packet = Packet::new(message.test()); + message.encode(&mut buf); + Some(OutgoingPacket::new(Some(buf.data), message.id(), message.length())) + } + } + #[inline] pub fn cleanup(&mut self) { self.walk_dir = -1; diff --git a/src/prot.rs b/src/prot.rs index f5cb121..9e285df 100644 --- a/src/prot.rs +++ b/src/prot.rs @@ -1,4 +1,5 @@ #![allow(non_camel_case_types)] +#![allow(dead_code)] use wasm_bindgen::prelude::wasm_bindgen; @@ -250,6 +251,16 @@ pub enum ServerInternalProt { UPDATE_ZONE_PARTIAL_FOLLOWS = 7, // NXT naming UPDATE_ZONE_FULL_FOLLOWS = 135, // NXT naming UPDATE_ZONE_PARTIAL_ENCLOSED = 162, // NXT naming + LOC_MERGE = 23, // based on runescript command p_locmerge + LOC_ANIM = 42, // NXT naming + OBJ_DEL = 49, // NXT naming + OBJ_REVEAL = 50, // NXT naming + LOC_ADD_CHANGE = 59, // NXT naming + MAP_PROJANIM = 69, // NXT naming + LOC_DEL = 76, // NXT naming + OBJ_COUNT = 151, // NXT naming + MAP_ANIM = 191, // NXT naming + OBJ_ADD = 223, // NXT naming } #[repr(u8)] From ec387c039bfcbecec63ba4cb436717925e1c86ac Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 30 Mar 2025 21:00:03 -0400 Subject: [PATCH 04/14] feat: a whole lotta inlining --- src/in/anticheat.rs | 45 +++++++++++++++++++++++++ src/in/chat_setmode.rs | 3 ++ src/in/client_cheat.rs | 3 ++ src/in/close_modal.rs | 3 ++ src/in/event.rs | 6 ++++ src/in/friend.rs | 6 ++++ src/in/idle_timer.rs | 3 ++ src/in/if_button.rs | 3 ++ src/in/if_playerdesign.rs | 9 ++++- src/in/ignore.rs | 6 ++++ src/in/inv_button.rs | 6 ++++ src/in/message_private.rs | 3 ++ src/in/message_public.rs | 3 ++ src/in/move_click.rs | 3 ++ src/in/no_timeout.rs | 3 ++ src/in/opheld.rs | 9 +++++ src/in/oploc.rs | 9 +++++ src/in/opnpc.rs | 9 +++++ src/in/opobj.rs | 9 +++++ src/in/opplayer.rs | 9 +++++ src/in/rebuild_getmaps.rs | 3 ++ src/in/reportabuse.rs | 4 +++ src/in/resume_countdialog.rs | 3 ++ src/in/resume_pausebutton.rs | 4 +++ src/in/tutorial_clickside.rs | 3 ++ src/lib.rs | 3 -- src/message.rs | 4 +++ src/out/cam_lookat.rs | 6 ++++ src/out/cam_moveto.rs | 6 ++++ src/out/cam_reset.rs | 6 ++++ src/out/cam_shake.rs | 6 ++++ src/out/chat_filter_settings.rs | 6 ++++ src/out/count_dialog.rs | 6 ++++ src/out/data_land.rs | 12 +++++++ src/out/data_loc.rs | 12 +++++++ src/out/enable_tracking.rs | 6 ++++ src/out/finish_tracking.rs | 6 ++++ src/out/hint_arrow.rs | 6 ++++ src/out/if_close.rs | 6 ++++ src/out/if_openchat.rs | 6 ++++ src/out/if_openmain.rs | 6 ++++ src/out/if_openmainside.rs | 6 ++++ src/out/if_openside.rs | 6 ++++ src/out/if_setanim.rs | 6 ++++ src/out/if_setcolour.rs | 6 ++++ src/out/if_sethide.rs | 6 ++++ src/out/if_setmodel.rs | 6 ++++ src/out/if_setnpchead.rs | 6 ++++ src/out/if_setobject.rs | 6 ++++ src/out/if_setplayerhead.rs | 6 ++++ src/out/if_setposition.rs | 6 ++++ src/out/if_setrecol.rs | 6 ++++ src/out/if_settab.rs | 6 ++++ src/out/if_settabactive.rs | 6 ++++ src/out/if_settext.rs | 6 ++++ src/out/last_login_info.rs | 6 ++++ src/out/loc_addchange.rs | 6 ++++ src/out/loc_anim.rs | 6 ++++ src/out/loc_del.rs | 6 ++++ src/out/loc_merge.rs | 6 ++++ src/out/logout.rs | 6 ++++ src/out/map_anim.rs | 6 ++++ src/out/map_projanim.rs | 6 ++++ src/out/message_game.rs | 6 ++++ src/out/message_private.rs | 6 ++++ src/out/midi_jingle.rs | 6 ++++ src/out/midi_song.rs | 6 ++++ src/out/obj_add.rs | 6 ++++ src/out/obj_count.rs | 6 ++++ src/out/obj_del.rs | 6 ++++ src/out/obj_reveal.rs | 6 ++++ src/out/rebuild_normal.rs | 13 ++++--- src/out/reset_anims.rs | 6 ++++ src/out/reset_clientvarcache.rs | 6 ++++ src/out/set_multiway.rs | 6 ++++ src/out/synth_sound.rs | 6 ++++ src/out/tut_flash.rs | 6 ++++ src/out/tut_open.rs | 6 ++++ src/out/unset_map_flag.rs | 6 ++++ src/out/update_friendlist.rs | 6 ++++ src/out/update_ignorelist.rs | 6 ++++ src/out/update_inv_full.rs | 6 ++++ src/out/update_inv_partial.rs | 6 ++++ src/out/update_inv_stop_transmit.rs | 6 ++++ src/out/update_pid.rs | 6 ++++ src/out/update_reboot_timer.rs | 6 ++++ src/out/update_runenergy.rs | 6 ++++ src/out/update_runweight.rs | 6 ++++ src/out/update_stat.rs | 6 ++++ src/out/update_zone_full_follows.rs | 6 ++++ src/out/update_zone_partial_enclosed.rs | 6 ++++ src/out/update_zone_partial_follows.rs | 6 ++++ src/out/varp_large.rs | 6 ++++ src/out/varp_small.rs | 6 ++++ src/pack.rs | 3 ++ 95 files changed, 587 insertions(+), 11 deletions(-) diff --git a/src/in/anticheat.rs b/src/in/anticheat.rs index b4db400..7c7bcc1 100644 --- a/src/in/anticheat.rs +++ b/src/in/anticheat.rs @@ -9,16 +9,19 @@ pub struct AnticheatOp1 {} #[wasm_bindgen] impl AnticheatOp1 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatOp1 { return AnticheatOp1 {}; } } impl MessageDecoder for AnticheatOp1 { + #[inline] fn length() -> i32 { return 4; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp1 { return AnticheatOp1::new(); } @@ -32,16 +35,19 @@ pub struct AnticheatOp2 {} #[wasm_bindgen] impl AnticheatOp2 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatOp2 { return AnticheatOp2 {}; } } impl MessageDecoder for AnticheatOp2 { + #[inline] fn length() -> i32 { return 4; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp2 { return AnticheatOp2::new(); } @@ -55,16 +61,19 @@ pub struct AnticheatOp3 {} #[wasm_bindgen] impl AnticheatOp3 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatOp3 { return AnticheatOp3 {}; } } impl MessageDecoder for AnticheatOp3 { + #[inline] fn length() -> i32 { return 3; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp3 { return AnticheatOp3::new(); } @@ -78,16 +87,19 @@ pub struct AnticheatOp4 {} #[wasm_bindgen] impl AnticheatOp4 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatOp4 { return AnticheatOp4 {}; } } impl MessageDecoder for AnticheatOp4 { + #[inline] fn length() -> i32 { return 2; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp4 { return AnticheatOp4::new(); } @@ -101,16 +113,19 @@ pub struct AnticheatOp5 {} #[wasm_bindgen] impl AnticheatOp5 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatOp5 { return AnticheatOp5 {}; } } impl MessageDecoder for AnticheatOp5 { + #[inline] fn length() -> i32 { return 0; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp5 { return AnticheatOp5::new(); } @@ -124,16 +139,19 @@ pub struct AnticheatOp6 {} #[wasm_bindgen] impl AnticheatOp6 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatOp6 { return AnticheatOp6 {}; } } impl MessageDecoder for AnticheatOp6 { + #[inline] fn length() -> i32 { return 4; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp6 { return AnticheatOp6::new(); } @@ -147,16 +165,19 @@ pub struct AnticheatOp7 {} #[wasm_bindgen] impl AnticheatOp7 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatOp7 { return AnticheatOp7 {}; } } impl MessageDecoder for AnticheatOp7 { + #[inline] fn length() -> i32 { return 4; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp7 { return AnticheatOp7::new(); } @@ -170,16 +191,19 @@ pub struct AnticheatOp8 {} #[wasm_bindgen] impl AnticheatOp8 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatOp8 { return AnticheatOp8 {}; } } impl MessageDecoder for AnticheatOp8 { + #[inline] fn length() -> i32 { return 2; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp8 { return AnticheatOp8::new(); } @@ -193,16 +217,19 @@ pub struct AnticheatOp9 {} #[wasm_bindgen] impl AnticheatOp9 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatOp9 { return AnticheatOp9 {}; } } impl MessageDecoder for AnticheatOp9 { + #[inline] fn length() -> i32 { return 1; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp9 { return AnticheatOp9::new(); } @@ -216,16 +243,19 @@ pub struct AnticheatCycle1 {} #[wasm_bindgen] impl AnticheatCycle1 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatCycle1 { return AnticheatCycle1 {}; } } impl MessageDecoder for AnticheatCycle1 { + #[inline] fn length() -> i32 { return 1; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle1 { return AnticheatCycle1::new(); } @@ -239,16 +269,19 @@ pub struct AnticheatCycle2 {} #[wasm_bindgen] impl AnticheatCycle2 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatCycle2 { return AnticheatCycle2 {}; } } impl MessageDecoder for AnticheatCycle2 { + #[inline] fn length() -> i32 { return -1; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle2 { return AnticheatCycle2::new(); } @@ -262,16 +295,19 @@ pub struct AnticheatCycle3 {} #[wasm_bindgen] impl AnticheatCycle3 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatCycle3 { return AnticheatCycle3 {}; } } impl MessageDecoder for AnticheatCycle3 { + #[inline] fn length() -> i32 { return 3; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle3 { return AnticheatCycle3::new(); } @@ -285,16 +321,19 @@ pub struct AnticheatCycle4 {} #[wasm_bindgen] impl AnticheatCycle4 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatCycle4 { return AnticheatCycle4 {}; } } impl MessageDecoder for AnticheatCycle4 { + #[inline] fn length() -> i32 { return 4; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle4 { return AnticheatCycle4::new(); } @@ -308,16 +347,19 @@ pub struct AnticheatCycle5 {} #[wasm_bindgen] impl AnticheatCycle5 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatCycle5 { return AnticheatCycle5 {}; } } impl MessageDecoder for AnticheatCycle5 { + #[inline] fn length() -> i32 { return 0; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle5 { return AnticheatCycle5::new(); } @@ -331,16 +373,19 @@ pub struct AnticheatCycle6 {} #[wasm_bindgen] impl AnticheatCycle6 { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> AnticheatCycle6 { return AnticheatCycle6 {}; } } impl MessageDecoder for AnticheatCycle6 { + #[inline] fn length() -> i32 { return -1; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle6 { return AnticheatCycle6::new(); } diff --git a/src/in/chat_setmode.rs b/src/in/chat_setmode.rs index ab77adf..6a58818 100644 --- a/src/in/chat_setmode.rs +++ b/src/in/chat_setmode.rs @@ -16,6 +16,7 @@ pub struct ChatSetMode { #[wasm_bindgen] impl ChatSetMode { #[wasm_bindgen(constructor)] + #[inline] pub fn new( public: u8, private: u8, @@ -30,10 +31,12 @@ impl ChatSetMode { } impl MessageDecoder for ChatSetMode { + #[inline] fn length() -> i32 { return 3; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> ChatSetMode { return ChatSetMode::new( buf.g1(), diff --git a/src/in/client_cheat.rs b/src/in/client_cheat.rs index d854a55..61e86ec 100644 --- a/src/in/client_cheat.rs +++ b/src/in/client_cheat.rs @@ -12,6 +12,7 @@ pub struct ClientCheat { #[wasm_bindgen] impl ClientCheat { #[wasm_bindgen(constructor)] + #[inline] pub fn new(input: String) -> ClientCheat { return ClientCheat { input, @@ -20,10 +21,12 @@ impl ClientCheat { } impl MessageDecoder for ClientCheat { + #[inline] fn length() -> i32 { return -1; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> ClientCheat { return ClientCheat::new(buf.gjstr(10)); } diff --git a/src/in/close_modal.rs b/src/in/close_modal.rs index b53942b..7ddc540 100644 --- a/src/in/close_modal.rs +++ b/src/in/close_modal.rs @@ -9,16 +9,19 @@ pub struct CloseModal {} #[wasm_bindgen] impl CloseModal { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> CloseModal { return CloseModal {} } } impl MessageDecoder for CloseModal { + #[inline] fn length() -> i32 { return 0; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> CloseModal { return CloseModal::new(); } diff --git a/src/in/event.rs b/src/in/event.rs index 5860f3c..214baff 100644 --- a/src/in/event.rs +++ b/src/in/event.rs @@ -12,6 +12,7 @@ pub struct EventTracking { #[wasm_bindgen] impl EventTracking { #[wasm_bindgen(constructor)] + #[inline] pub fn new(bytes: Vec) -> EventTracking { return EventTracking { bytes, @@ -20,10 +21,12 @@ impl EventTracking { } impl MessageDecoder for EventTracking { + #[inline] fn length() -> i32 { return -2; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> EventTracking { return EventTracking::new(buf.data.clone()); } @@ -46,6 +49,7 @@ pub struct EventCameraPosition { #[wasm_bindgen] impl EventCameraPosition { #[wasm_bindgen(constructor)] + #[inline] pub fn new( pitch: i32, yaw: i32, @@ -62,10 +66,12 @@ impl EventCameraPosition { } impl MessageDecoder for EventCameraPosition { + #[inline] fn length() -> i32 { return 6; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> EventCameraPosition { return EventCameraPosition::new( buf.g2() as i32, diff --git a/src/in/friend.rs b/src/in/friend.rs index 3b2f994..39b6e4c 100644 --- a/src/in/friend.rs +++ b/src/in/friend.rs @@ -12,6 +12,7 @@ pub struct FriendListAdd { #[wasm_bindgen] impl FriendListAdd { #[wasm_bindgen(constructor)] + #[inline] pub fn new(username: i64) -> FriendListAdd { return FriendListAdd { username, @@ -20,10 +21,12 @@ impl FriendListAdd { } impl MessageDecoder for FriendListAdd { + #[inline] fn length() -> i32 { return 8; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> FriendListAdd { return FriendListAdd::new(buf.g8s()); } @@ -40,6 +43,7 @@ pub struct FriendListDel { #[wasm_bindgen] impl FriendListDel { #[wasm_bindgen(constructor)] + #[inline] pub fn new(username: i64) -> FriendListDel { return FriendListDel { username, @@ -48,10 +52,12 @@ impl FriendListDel { } impl MessageDecoder for FriendListDel { + #[inline] fn length() -> i32 { return 8; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> FriendListDel { return FriendListDel::new(buf.g8s()); } diff --git a/src/in/idle_timer.rs b/src/in/idle_timer.rs index 93ab5c4..ddf02b8 100644 --- a/src/in/idle_timer.rs +++ b/src/in/idle_timer.rs @@ -9,16 +9,19 @@ pub struct IdleTimer {} #[wasm_bindgen] impl IdleTimer { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> IdleTimer { return IdleTimer {} } } impl MessageDecoder for IdleTimer { + #[inline] fn length() -> i32 { return 0; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> IdleTimer { return IdleTimer::new(); } diff --git a/src/in/if_button.rs b/src/in/if_button.rs index 58c6192..8d2c61c 100644 --- a/src/in/if_button.rs +++ b/src/in/if_button.rs @@ -12,6 +12,7 @@ pub struct IfButton { #[wasm_bindgen] impl IfButton { #[wasm_bindgen(constructor)] + #[inline] pub fn new(component: u16) -> IfButton { return IfButton { component, @@ -20,10 +21,12 @@ impl IfButton { } impl MessageDecoder for IfButton { + #[inline] fn length() -> i32 { return 2; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> IfButton { return IfButton::new(buf.g2()); } diff --git a/src/in/if_playerdesign.rs b/src/in/if_playerdesign.rs index 1aa1b4a..05b71fe 100644 --- a/src/in/if_playerdesign.rs +++ b/src/in/if_playerdesign.rs @@ -16,7 +16,12 @@ pub struct IfPlayerDesign { #[wasm_bindgen] impl IfPlayerDesign { #[wasm_bindgen(constructor)] - pub fn new(gender: u8, idkit: Vec, color: Vec) -> IfPlayerDesign { + #[inline] + pub fn new( + gender: u8, + idkit: Vec, + color: Vec + ) -> IfPlayerDesign { return IfPlayerDesign { gender, idkit, @@ -26,10 +31,12 @@ impl IfPlayerDesign { } impl MessageDecoder for IfPlayerDesign { + #[inline] fn length() -> i32 { return 13; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> IfPlayerDesign { let gender: u8 = buf.g1(); diff --git a/src/in/ignore.rs b/src/in/ignore.rs index d89c804..e1dda2d 100644 --- a/src/in/ignore.rs +++ b/src/in/ignore.rs @@ -12,6 +12,7 @@ pub struct IgnoreListAdd { #[wasm_bindgen] impl IgnoreListAdd { #[wasm_bindgen(constructor)] + #[inline] pub fn new(username: i64) -> IgnoreListAdd { return IgnoreListAdd { username, @@ -20,10 +21,12 @@ impl IgnoreListAdd { } impl MessageDecoder for IgnoreListAdd { + #[inline] fn length() -> i32 { return 8; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> IgnoreListAdd { return IgnoreListAdd::new(buf.g8s()); } @@ -40,6 +43,7 @@ pub struct IgnoreListDel { #[wasm_bindgen] impl IgnoreListDel { #[wasm_bindgen(constructor)] + #[inline] pub fn new(username: i64) -> IgnoreListDel { return IgnoreListDel { username, @@ -48,10 +52,12 @@ impl IgnoreListDel { } impl MessageDecoder for IgnoreListDel { + #[inline] fn length() -> i32 { return 8; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> IgnoreListDel { return IgnoreListDel::new(buf.g8s()); } diff --git a/src/in/inv_button.rs b/src/in/inv_button.rs index 667ab4c..f17dde8 100644 --- a/src/in/inv_button.rs +++ b/src/in/inv_button.rs @@ -18,6 +18,7 @@ pub struct InvButton { #[wasm_bindgen] impl InvButton { #[wasm_bindgen(constructor)] + #[inline] pub fn new( op: u8, obj: u16, @@ -34,10 +35,12 @@ impl InvButton { } impl MessageDecoder for InvButton { + #[inline] fn length() -> i32 { return 6; } + #[inline] fn decode(prot: ClientProt, buf: &mut Packet) -> InvButton { let op: u8 = match prot { ClientProt::INV_BUTTON1 => 1, @@ -71,6 +74,7 @@ pub struct InvButtonD { #[wasm_bindgen] impl InvButtonD { #[wasm_bindgen(constructor)] + #[inline] pub fn new( component: u16, slot: u16, @@ -85,10 +89,12 @@ impl InvButtonD { } impl MessageDecoder for InvButtonD { + #[inline] fn length() -> i32 { return 6; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> InvButtonD { return InvButtonD::new( buf.g2(), diff --git a/src/in/message_private.rs b/src/in/message_private.rs index feebcb6..0a5fbd4 100644 --- a/src/in/message_private.rs +++ b/src/in/message_private.rs @@ -14,6 +14,7 @@ pub struct MessagePrivate { #[wasm_bindgen] impl MessagePrivate { #[wasm_bindgen(constructor)] + #[inline] pub fn new( username: i64, input: Vec, @@ -26,10 +27,12 @@ impl MessagePrivate { } impl MessageDecoder for MessagePrivate { + #[inline] fn length() -> i32 { return -1; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> MessagePrivate { return MessagePrivate::new( buf.g8s(), diff --git a/src/in/message_public.rs b/src/in/message_public.rs index 819b6fd..4157bf2 100644 --- a/src/in/message_public.rs +++ b/src/in/message_public.rs @@ -16,6 +16,7 @@ pub struct MessagePublic { #[wasm_bindgen] impl MessagePublic { #[wasm_bindgen(constructor)] + #[inline] pub fn new( color: u8, effect: u8, @@ -30,10 +31,12 @@ impl MessagePublic { } impl MessageDecoder for MessagePublic { + #[inline] fn length() -> i32 { return -1; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> MessagePublic { return MessagePublic::new( buf.g1(), diff --git a/src/in/move_click.rs b/src/in/move_click.rs index 02e6773..da7fb36 100644 --- a/src/in/move_click.rs +++ b/src/in/move_click.rs @@ -17,6 +17,7 @@ pub struct MoveClick { #[wasm_bindgen] impl MoveClick { #[wasm_bindgen(constructor)] + #[inline] pub fn new( ctrl: bool, op: bool, @@ -31,10 +32,12 @@ impl MoveClick { } impl MessageDecoder for MoveClick { + #[inline] fn length() -> i32 { return -1; } + #[inline] fn decode(prot: ClientProt, buf: &mut Packet) -> MoveClick { let ctrl: bool = buf.g1() == 1; let x: u16 = buf.g2(); diff --git a/src/in/no_timeout.rs b/src/in/no_timeout.rs index 43b5557..595c656 100644 --- a/src/in/no_timeout.rs +++ b/src/in/no_timeout.rs @@ -9,16 +9,19 @@ pub struct NoTimeout {} #[wasm_bindgen] impl NoTimeout { #[wasm_bindgen(constructor)] + #[inline] pub fn new() -> NoTimeout { return NoTimeout {}; } } impl MessageDecoder for NoTimeout { + #[inline] fn length() -> i32 { return 0; } + #[inline] fn decode(_: ClientProt, _: &mut Packet) -> NoTimeout { return NoTimeout::new(); } diff --git a/src/in/opheld.rs b/src/in/opheld.rs index 7ba02cc..d5be104 100644 --- a/src/in/opheld.rs +++ b/src/in/opheld.rs @@ -18,6 +18,7 @@ pub struct OpHeld { #[wasm_bindgen] impl OpHeld { #[wasm_bindgen(constructor)] + #[inline] pub fn new( op: u8, obj: u16, @@ -34,10 +35,12 @@ impl OpHeld { } impl MessageDecoder for OpHeld { + #[inline] fn length() -> i32 { return 6; } + #[inline] fn decode(prot: ClientProt, buf: &mut Packet) -> OpHeld { let op: u8 = match prot { ClientProt::OPHELD1 => 1, @@ -73,6 +76,7 @@ pub struct OpHeldT { #[wasm_bindgen] impl OpHeldT { #[wasm_bindgen(constructor)] + #[inline] pub fn new( obj: u16, slot: u16, @@ -89,10 +93,12 @@ impl OpHeldT { } impl MessageDecoder for OpHeldT { + #[inline] fn length() -> i32 { return 8; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> OpHeldT { return OpHeldT::new( buf.g2(), @@ -124,6 +130,7 @@ pub struct OpHeldU { #[wasm_bindgen] impl OpHeldU { #[wasm_bindgen(constructor)] + #[inline] pub fn new( obj: u16, slot: u16, @@ -144,10 +151,12 @@ impl OpHeldU { } impl MessageDecoder for OpHeldU { + #[inline] fn length() -> i32 { return 12; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> OpHeldU { return OpHeldU::new( buf.g2(), diff --git a/src/in/oploc.rs b/src/in/oploc.rs index fe97dc5..49db093 100644 --- a/src/in/oploc.rs +++ b/src/in/oploc.rs @@ -18,6 +18,7 @@ pub struct OpLoc { #[wasm_bindgen] impl OpLoc { #[wasm_bindgen(constructor)] + #[inline] pub fn new( op: u8, x: u16, @@ -34,10 +35,12 @@ impl OpLoc { } impl MessageDecoder for OpLoc { + #[inline] fn length() -> i32 { return 6; } + #[inline] fn decode(prot: ClientProt, buf: &mut Packet) -> OpLoc { let op: u8 = match prot { ClientProt::OPLOC1 => 1, @@ -73,6 +76,7 @@ pub struct OpLocT { #[wasm_bindgen] impl OpLocT { #[wasm_bindgen(constructor)] + #[inline] pub fn new( x: u16, z: u16, @@ -89,10 +93,12 @@ impl OpLocT { } impl MessageDecoder for OpLocT { + #[inline] fn length() -> i32 { return 8; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> OpLocT { return OpLocT::new( buf.g2(), @@ -124,6 +130,7 @@ pub struct OpLocU { #[wasm_bindgen] impl OpLocU { #[wasm_bindgen(constructor)] + #[inline] pub fn new( x: u16, z: u16, @@ -144,10 +151,12 @@ impl OpLocU { } impl MessageDecoder for OpLocU { + #[inline] fn length() -> i32 { return 12; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> OpLocU { return OpLocU::new( buf.g2(), diff --git a/src/in/opnpc.rs b/src/in/opnpc.rs index 65c6e37..fd7b534 100644 --- a/src/in/opnpc.rs +++ b/src/in/opnpc.rs @@ -14,6 +14,7 @@ pub struct OpNpc { #[wasm_bindgen] impl OpNpc { #[wasm_bindgen(constructor)] + #[inline] pub fn new( op: u8, nid: u16, @@ -26,10 +27,12 @@ impl OpNpc { } impl MessageDecoder for OpNpc { + #[inline] fn length() -> i32 { return 2; } + #[inline] fn decode(prot: ClientProt, buf: &mut Packet) -> OpNpc { let op: u8 = match prot { ClientProt::OPNPC1 => 1, @@ -59,6 +62,7 @@ pub struct OpNpcT { #[wasm_bindgen] impl OpNpcT { #[wasm_bindgen(constructor)] + #[inline] pub fn new( nid: u16, spell: u16, @@ -71,10 +75,12 @@ impl OpNpcT { } impl MessageDecoder for OpNpcT { + #[inline] fn length() -> i32 { return 4; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> OpNpcT { return OpNpcT::new( buf.g2(), @@ -100,6 +106,7 @@ pub struct OpNpcU { #[wasm_bindgen] impl OpNpcU { #[wasm_bindgen(constructor)] + #[inline] pub fn new( nid: u16, use_obj: u16, @@ -116,10 +123,12 @@ impl OpNpcU { } impl MessageDecoder for OpNpcU { + #[inline] fn length() -> i32 { return 8; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> OpNpcU { return OpNpcU::new( buf.g2(), diff --git a/src/in/opobj.rs b/src/in/opobj.rs index f0f47ff..5b791a9 100644 --- a/src/in/opobj.rs +++ b/src/in/opobj.rs @@ -18,6 +18,7 @@ pub struct OpObj { #[wasm_bindgen] impl OpObj { #[wasm_bindgen(constructor)] + #[inline] pub fn new( op: u8, x: u16, @@ -34,10 +35,12 @@ impl OpObj { } impl MessageDecoder for OpObj { + #[inline] fn length() -> i32 { return 6; } + #[inline] fn decode(prot: ClientProt, buf: &mut Packet) -> OpObj { let op: u8 = match prot { ClientProt::OPOBJ1 => 1, @@ -73,6 +76,7 @@ pub struct OpObjT { #[wasm_bindgen] impl OpObjT { #[wasm_bindgen(constructor)] + #[inline] pub fn new( x: u16, z: u16, @@ -89,10 +93,12 @@ impl OpObjT { } impl MessageDecoder for OpObjT { + #[inline] fn length() -> i32 { return 8; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> OpObjT { return OpObjT::new( buf.g2(), @@ -124,6 +130,7 @@ pub struct OpObjU { #[wasm_bindgen] impl OpObjU { #[wasm_bindgen(constructor)] + #[inline] pub fn new( x: u16, z: u16, @@ -144,10 +151,12 @@ impl OpObjU { } impl MessageDecoder for OpObjU { + #[inline] fn length() -> i32 { return 12; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> OpObjU { return OpObjU::new( buf.g2(), diff --git a/src/in/opplayer.rs b/src/in/opplayer.rs index 09c7532..bd55a14 100644 --- a/src/in/opplayer.rs +++ b/src/in/opplayer.rs @@ -14,6 +14,7 @@ pub struct OpPlayer { #[wasm_bindgen] impl OpPlayer { #[wasm_bindgen(constructor)] + #[inline] pub fn new( op: u8, pid: u16, @@ -26,10 +27,12 @@ impl OpPlayer { } impl MessageDecoder for OpPlayer { + #[inline] fn length() -> i32 { return 2; } + #[inline] fn decode(prot: ClientProt, buf: &mut Packet) -> OpPlayer { let op: u8 = match prot { ClientProt::OPPLAYER1 => 1, @@ -58,6 +61,7 @@ pub struct OpPlayerT { #[wasm_bindgen] impl OpPlayerT { #[wasm_bindgen(constructor)] + #[inline] pub fn new( pid: u16, spell: u16, @@ -70,10 +74,12 @@ impl OpPlayerT { } impl MessageDecoder for OpPlayerT { + #[inline] fn length() -> i32 { return 4; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> OpPlayerT { return OpPlayerT::new( buf.g2(), @@ -99,6 +105,7 @@ pub struct OpPlayerU { #[wasm_bindgen] impl OpPlayerU { #[wasm_bindgen(constructor)] + #[inline] pub fn new( pid: u16, use_obj: u16, @@ -115,10 +122,12 @@ impl OpPlayerU { } impl MessageDecoder for OpPlayerU { + #[inline] fn length() -> i32 { return 8; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> OpPlayerU { return OpPlayerU::new( buf.g2(), diff --git a/src/in/rebuild_getmaps.rs b/src/in/rebuild_getmaps.rs index d0ab2c4..f33499f 100644 --- a/src/in/rebuild_getmaps.rs +++ b/src/in/rebuild_getmaps.rs @@ -12,6 +12,7 @@ pub struct RebuildGetMaps { #[wasm_bindgen] impl RebuildGetMaps { #[wasm_bindgen(constructor)] + #[inline] pub fn new(maps: Vec) -> RebuildGetMaps { return RebuildGetMaps { maps, @@ -20,10 +21,12 @@ impl RebuildGetMaps { } impl MessageDecoder for RebuildGetMaps { + #[inline] fn length() -> i32 { return -1; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> RebuildGetMaps { let mut maps: Vec = vec![0; buf.data.len() / 3]; for index in 0..maps.len() { diff --git a/src/in/reportabuse.rs b/src/in/reportabuse.rs index 0ccb5fe..a10a90c 100644 --- a/src/in/reportabuse.rs +++ b/src/in/reportabuse.rs @@ -15,6 +15,8 @@ pub struct ReportAbuse { #[wasm_bindgen] impl ReportAbuse { + #[wasm_bindgen(constructor)] + #[inline] pub fn new( offender: i64, reason: u8, @@ -29,10 +31,12 @@ impl ReportAbuse { } impl MessageDecoder for ReportAbuse { + #[inline] fn length() -> i32 { return 10; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> ReportAbuse { return ReportAbuse::new( buf.g8s(), diff --git a/src/in/resume_countdialog.rs b/src/in/resume_countdialog.rs index a426ce5..eefb562 100644 --- a/src/in/resume_countdialog.rs +++ b/src/in/resume_countdialog.rs @@ -12,6 +12,7 @@ pub struct ResumePCountDialog { #[wasm_bindgen] impl ResumePCountDialog { #[wasm_bindgen(constructor)] + #[inline] pub fn new(input: i32) -> ResumePCountDialog { return ResumePCountDialog { input, @@ -20,10 +21,12 @@ impl ResumePCountDialog { } impl MessageDecoder for ResumePCountDialog { + #[inline] fn length() -> i32 { return 4; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> ResumePCountDialog { return ResumePCountDialog::new(buf.g4s()); } diff --git a/src/in/resume_pausebutton.rs b/src/in/resume_pausebutton.rs index d4e8974..e3dad49 100644 --- a/src/in/resume_pausebutton.rs +++ b/src/in/resume_pausebutton.rs @@ -11,6 +11,8 @@ pub struct ResumePauseButton { #[wasm_bindgen] impl ResumePauseButton { + #[wasm_bindgen(constructor)] + #[inline] pub fn new(component: u16) -> ResumePauseButton { return ResumePauseButton { component, @@ -19,10 +21,12 @@ impl ResumePauseButton { } impl MessageDecoder for ResumePauseButton { + #[inline] fn length() -> i32 { return 2; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> ResumePauseButton { return ResumePauseButton::new(buf.g2()); } diff --git a/src/in/tutorial_clickside.rs b/src/in/tutorial_clickside.rs index bd7e667..2ef529e 100644 --- a/src/in/tutorial_clickside.rs +++ b/src/in/tutorial_clickside.rs @@ -12,6 +12,7 @@ pub struct TutorialClickSide { #[wasm_bindgen] impl TutorialClickSide { #[wasm_bindgen(constructor)] + #[inline] pub fn new(tab: u8) -> TutorialClickSide { return TutorialClickSide { tab, @@ -20,10 +21,12 @@ impl TutorialClickSide { } impl MessageDecoder for TutorialClickSide { + #[inline] fn length() -> i32 { return 1; } + #[inline] fn decode(_: ClientProt, buf: &mut Packet) -> TutorialClickSide { return TutorialClickSide::new(buf.g1()); } diff --git a/src/lib.rs b/src/lib.rs index 179be79..1ef9a06 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1307,9 +1307,6 @@ pub unsafe fn next_buffered_write(pid: i32) -> Option { // ---- decoders static PACKET_LOOKUP: Lazy>> = Lazy::new(|| { - use ClientInternalProt::*; - use ClientProt::*; - let mut lookup: HashMap> = HashMap::new(); lookup.insert(ClientInternalProt::CLIENT_CHEAT as i32, Some(IncomingPacket::new(ClientProt::CLIENT_CHEAT as i32, ClientCheat::length()))); lookup.insert(ClientInternalProt::CLOSE_MODAL as i32, Some(IncomingPacket::new(ClientProt::CLOSE_MODAL as i32, CloseModal::length()))); diff --git a/src/message.rs b/src/message.rs index c9af920..579f6a2 100644 --- a/src/message.rs +++ b/src/message.rs @@ -33,6 +33,7 @@ pub struct OutgoingPacket { } impl OutgoingPacket { + #[inline] pub fn new( bytes: Option>, id: i32, @@ -56,6 +57,7 @@ pub struct IncomingPacket { } impl IncomingPacket { + #[inline] pub fn new( id: i32, length: i32 @@ -564,10 +566,12 @@ impl NpcInfoChangeType { } impl InfoMessage for NpcInfoChangeType { + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.change_type); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/cam_lookat.rs b/src/out/cam_lookat.rs index 0c2802d..18e8d91 100644 --- a/src/out/cam_lookat.rs +++ b/src/out/cam_lookat.rs @@ -12,6 +12,7 @@ pub struct CamLookAt { } impl CamLookAt { + #[inline] pub fn new( x: i32, z: i32, @@ -30,18 +31,22 @@ impl CamLookAt { } impl MessageEncoder for CamLookAt { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::CAM_LOOKAT as i32; } + #[inline] fn length(&self) -> i32 { return 6; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); buf.p1(self.z); @@ -50,6 +55,7 @@ impl MessageEncoder for CamLookAt { buf.p1(self.multiplier); } + #[inline] fn test(&self) -> usize { return 6; } diff --git a/src/out/cam_moveto.rs b/src/out/cam_moveto.rs index e8f7c1f..75af2a8 100644 --- a/src/out/cam_moveto.rs +++ b/src/out/cam_moveto.rs @@ -12,6 +12,7 @@ pub struct CamMoveTo { } impl CamMoveTo { + #[inline] pub fn new( x: i32, z: i32, @@ -30,18 +31,22 @@ impl CamMoveTo { } impl MessageEncoder for CamMoveTo { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::CAM_MOVETO as i32; } + #[inline] fn length(&self) -> i32 { return 6; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); buf.p1(self.z); @@ -50,6 +55,7 @@ impl MessageEncoder for CamMoveTo { buf.p1(self.multiplier); } + #[inline] fn test(&self) -> usize { return 6; } diff --git a/src/out/cam_reset.rs b/src/out/cam_reset.rs index 827fee4..36a8c7c 100644 --- a/src/out/cam_reset.rs +++ b/src/out/cam_reset.rs @@ -6,26 +6,32 @@ use crate::prot::ServerInternalProt; pub struct CamReset {} impl CamReset { + #[inline] pub fn new() -> CamReset { return CamReset {} } } impl MessageEncoder for CamReset { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::CAM_RESET as i32; } + #[inline] fn length(&self) -> i32 { return 0; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, _: &mut Packet) {} + #[inline] fn test(&self) -> usize { return 0; } diff --git a/src/out/cam_shake.rs b/src/out/cam_shake.rs index 3ed4e24..4f0024d 100644 --- a/src/out/cam_shake.rs +++ b/src/out/cam_shake.rs @@ -11,6 +11,7 @@ pub struct CamShake { } impl CamShake { + #[inline] pub fn new( shake: i32, jitter: i32, @@ -27,18 +28,22 @@ impl CamShake { } impl MessageEncoder for CamShake { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::CAM_SHAKE as i32; } + #[inline] fn length(&self) -> i32 { return 4; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.shake); // direction? buf.p1(self.jitter); @@ -46,6 +51,7 @@ impl MessageEncoder for CamShake { buf.p1(self.frequency); } + #[inline] fn test(&self) -> usize { return 4; } diff --git a/src/out/chat_filter_settings.rs b/src/out/chat_filter_settings.rs index e2f7436..cf274cf 100644 --- a/src/out/chat_filter_settings.rs +++ b/src/out/chat_filter_settings.rs @@ -10,6 +10,7 @@ pub struct ChatFilterSettings { } impl ChatFilterSettings { + #[inline] pub fn new( public: i32, private: i32, @@ -24,24 +25,29 @@ impl ChatFilterSettings { } impl MessageEncoder for ChatFilterSettings { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::CHAT_FILTER_SETTINGS as i32; } + #[inline] fn length(&self) -> i32 { return 3; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.public); buf.p1(self.private); buf.p1(self.trade); } + #[inline] fn test(&self) -> usize { return 3; } diff --git a/src/out/count_dialog.rs b/src/out/count_dialog.rs index 15aafc3..e166133 100644 --- a/src/out/count_dialog.rs +++ b/src/out/count_dialog.rs @@ -6,26 +6,32 @@ use crate::prot::ServerInternalProt; pub struct PCountDialog {} impl PCountDialog { + #[inline] pub fn new() -> PCountDialog { return PCountDialog {} } } impl MessageEncoder for PCountDialog { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::P_COUNTDIALOG as i32; } + #[inline] fn length(&self) -> i32 { return 0; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, _: &mut Packet) {} + #[inline] fn test(&self) -> usize { return 0; } diff --git a/src/out/data_land.rs b/src/out/data_land.rs index 7d753e1..8eb5c8b 100644 --- a/src/out/data_land.rs +++ b/src/out/data_land.rs @@ -12,6 +12,7 @@ pub struct DataLand { } impl DataLand { + #[inline] pub fn new( x: i32, z: i32, @@ -30,18 +31,22 @@ impl DataLand { } impl MessageEncoder for DataLand { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::DATA_LAND as i32; } + #[inline] fn length(&self) -> i32 { return -2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); buf.p1(self.z); @@ -50,6 +55,7 @@ impl MessageEncoder for DataLand { buf.pdata(&self.data, 0, self.data.len()); } + #[inline] fn test(&self) -> usize { return 6 + self.data.len(); } @@ -63,6 +69,7 @@ pub struct DataLandDone { } impl DataLandDone { + #[inline] pub fn new( x: i32, z: i32, @@ -75,23 +82,28 @@ impl DataLandDone { } impl MessageEncoder for DataLandDone { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::DATA_LAND_DONE as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); buf.p1(self.z); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/data_loc.rs b/src/out/data_loc.rs index bfe013f..31b2db9 100644 --- a/src/out/data_loc.rs +++ b/src/out/data_loc.rs @@ -12,6 +12,7 @@ pub struct DataLoc { } impl DataLoc { + #[inline] pub fn new( x: i32, z: i32, @@ -30,18 +31,22 @@ impl DataLoc { } impl MessageEncoder for DataLoc { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::DATA_LOC as i32; } + #[inline] fn length(&self) -> i32 { return -2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); buf.p1(self.z); @@ -50,6 +55,7 @@ impl MessageEncoder for DataLoc { buf.pdata(&self.data, 0, self.data.len()); } + #[inline] fn test(&self) -> usize { return 6 + self.data.len(); } @@ -63,6 +69,7 @@ pub struct DataLocDone { } impl DataLocDone { + #[inline] pub fn new( x: i32, z: i32, @@ -75,23 +82,28 @@ impl DataLocDone { } impl MessageEncoder for DataLocDone { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::DATA_LOC_DONE as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); buf.p1(self.z); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/enable_tracking.rs b/src/out/enable_tracking.rs index cfd15d7..4d20d4c 100644 --- a/src/out/enable_tracking.rs +++ b/src/out/enable_tracking.rs @@ -6,26 +6,32 @@ use crate::prot::ServerInternalProt; pub struct EnableTracking {} impl EnableTracking { + #[inline] pub fn new() -> EnableTracking { return EnableTracking {} } } impl MessageEncoder for EnableTracking { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::ENABLE_TRACKING as i32; } + #[inline] fn length(&self) -> i32 { return 0; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, _: &mut Packet) {} + #[inline] fn test(&self) -> usize { return 0; } diff --git a/src/out/finish_tracking.rs b/src/out/finish_tracking.rs index c483e80..ee9c995 100644 --- a/src/out/finish_tracking.rs +++ b/src/out/finish_tracking.rs @@ -6,26 +6,32 @@ use crate::prot::ServerInternalProt; pub struct FinishTracking {} impl FinishTracking { + #[inline] pub fn new() -> FinishTracking { return FinishTracking {} } } impl MessageEncoder for FinishTracking { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::FINISH_TRACKING as i32; } + #[inline] fn length(&self) -> i32 { return 0; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, _: &mut Packet) {} + #[inline] fn test(&self) -> usize { return 0; } diff --git a/src/out/hint_arrow.rs b/src/out/hint_arrow.rs index 5dbc217..9268e24 100644 --- a/src/out/hint_arrow.rs +++ b/src/out/hint_arrow.rs @@ -13,6 +13,7 @@ pub struct HintArrow { } impl HintArrow { + #[inline] pub fn new( arrow: i32, nid: i32, @@ -33,18 +34,22 @@ impl HintArrow { } impl MessageEncoder for HintArrow { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::HINT_ARROW as i32; } + #[inline] fn length(&self) -> i32 { return 6; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; // todo: what should priority be? } + #[inline] fn encode(&self, buf: &mut Packet) { match self.arrow { 1 => { @@ -79,6 +84,7 @@ impl MessageEncoder for HintArrow { } } + #[inline] fn test(&self) -> usize { return 6; } diff --git a/src/out/if_close.rs b/src/out/if_close.rs index 8649cf9..f4d2dcd 100644 --- a/src/out/if_close.rs +++ b/src/out/if_close.rs @@ -6,26 +6,32 @@ use crate::prot::ServerInternalProt; pub struct IfClose {} impl IfClose { + #[inline] pub fn new() -> IfClose { return IfClose {} } } impl MessageEncoder for IfClose { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_CLOSE as i32; } + #[inline] fn length(&self) -> i32 { return 0; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, _: &mut Packet) {} + #[inline] fn test(&self) -> usize { return 0; } diff --git a/src/out/if_openchat.rs b/src/out/if_openchat.rs index 60c6b11..1ab28d7 100644 --- a/src/out/if_openchat.rs +++ b/src/out/if_openchat.rs @@ -8,6 +8,7 @@ pub struct IfOpenChat { } impl IfOpenChat { + #[inline] pub fn new(component:i32) -> IfOpenChat { return IfOpenChat { component, @@ -16,22 +17,27 @@ impl IfOpenChat { } impl MessageEncoder for IfOpenChat { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_OPENCHAT as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/if_openmain.rs b/src/out/if_openmain.rs index 1c717f3..c72e3f4 100644 --- a/src/out/if_openmain.rs +++ b/src/out/if_openmain.rs @@ -8,6 +8,7 @@ pub struct IfOpenMain { } impl IfOpenMain { + #[inline] pub fn new(component:i32) -> IfOpenMain { return IfOpenMain { component, @@ -16,22 +17,27 @@ impl IfOpenMain { } impl MessageEncoder for IfOpenMain { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_OPENMAIN as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/if_openmainside.rs b/src/out/if_openmainside.rs index 559a531..2a0eddf 100644 --- a/src/out/if_openmainside.rs +++ b/src/out/if_openmainside.rs @@ -9,6 +9,7 @@ pub struct IfOpenMainSide { } impl IfOpenMainSide { + #[inline] pub fn new( main: i32, side: i32, @@ -21,23 +22,28 @@ impl IfOpenMainSide { } impl MessageEncoder for IfOpenMainSide { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_OPENMAIN_SIDE as i32; } + #[inline] fn length(&self) -> i32 { return 4; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.main); buf.p2(self.side); } + #[inline] fn test(&self) -> usize { return 4; } diff --git a/src/out/if_openside.rs b/src/out/if_openside.rs index 445b8fa..dad5330 100644 --- a/src/out/if_openside.rs +++ b/src/out/if_openside.rs @@ -8,6 +8,7 @@ pub struct IfOpenSide { } impl IfOpenSide { + #[inline] pub fn new(component:i32) -> IfOpenSide { return IfOpenSide { component, @@ -16,22 +17,27 @@ impl IfOpenSide { } impl MessageEncoder for IfOpenSide { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_OPENSIDE as i32 } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/if_setanim.rs b/src/out/if_setanim.rs index 9405196..d9b32be 100644 --- a/src/out/if_setanim.rs +++ b/src/out/if_setanim.rs @@ -9,6 +9,7 @@ pub struct IfSetAnim { } impl IfSetAnim { + #[inline] pub fn new( component: i32, seq: i32, @@ -21,23 +22,28 @@ impl IfSetAnim { } impl MessageEncoder for IfSetAnim { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETANIM as i32; } + #[inline] fn length(&self) -> i32 { return 4; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); buf.p2(self.seq); } + #[inline] fn test(&self) -> usize { return 4; } diff --git a/src/out/if_setcolour.rs b/src/out/if_setcolour.rs index a4fb89e..d9760d3 100644 --- a/src/out/if_setcolour.rs +++ b/src/out/if_setcolour.rs @@ -9,6 +9,7 @@ pub struct IfSetColour { } impl IfSetColour { + #[inline] pub fn new( component: i32, colour: i32, @@ -21,23 +22,28 @@ impl IfSetColour { } impl MessageEncoder for IfSetColour { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETCOLOUR as i32; } + #[inline] fn length(&self) -> i32 { return 4; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); buf.p2(self.colour); } + #[inline] fn test(&self) -> usize { return 4; } diff --git a/src/out/if_sethide.rs b/src/out/if_sethide.rs index b5960c0..cf43d8c 100644 --- a/src/out/if_sethide.rs +++ b/src/out/if_sethide.rs @@ -9,6 +9,7 @@ pub struct IfSetHide { } impl IfSetHide { + #[inline] pub fn new( component: i32, hidden: bool, @@ -21,23 +22,28 @@ impl IfSetHide { } impl MessageEncoder for IfSetHide { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETHIDE as i32; } + #[inline] fn length(&self) -> i32 { return 3; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); buf.p1(if self.hidden { 1 } else { 0 }); } + #[inline] fn test(&self) -> usize { return 3; } diff --git a/src/out/if_setmodel.rs b/src/out/if_setmodel.rs index 1b208b8..516f0a0 100644 --- a/src/out/if_setmodel.rs +++ b/src/out/if_setmodel.rs @@ -9,6 +9,7 @@ pub struct IfSetModel { } impl IfSetModel { + #[inline] pub fn new( component: i32, model: i32, @@ -21,23 +22,28 @@ impl IfSetModel { } impl MessageEncoder for IfSetModel { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETMODEL as i32; } + #[inline] fn length(&self) -> i32 { return 4; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); buf.p2(self.model); } + #[inline] fn test(&self) -> usize { return 4; } diff --git a/src/out/if_setnpchead.rs b/src/out/if_setnpchead.rs index 102e3e9..4c2155c 100644 --- a/src/out/if_setnpchead.rs +++ b/src/out/if_setnpchead.rs @@ -9,6 +9,7 @@ pub struct IfSetNpcHead { } impl IfSetNpcHead { + #[inline] pub fn new( component: i32, npc: i32, @@ -21,23 +22,28 @@ impl IfSetNpcHead { } impl MessageEncoder for IfSetNpcHead { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETNPCHEAD as i32; } + #[inline] fn length(&self) -> i32 { return 4; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); buf.p2(self.npc); } + #[inline] fn test(&self) -> usize { return 4; } diff --git a/src/out/if_setobject.rs b/src/out/if_setobject.rs index 3470e9e..d59006a 100644 --- a/src/out/if_setobject.rs +++ b/src/out/if_setobject.rs @@ -10,6 +10,7 @@ pub struct IfSetObject { } impl IfSetObject { + #[inline] pub fn new( component: i32, obj: i32, @@ -24,24 +25,29 @@ impl IfSetObject { } impl MessageEncoder for IfSetObject { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETOBJECT as i32; } + #[inline] fn length(&self) -> i32 { return 6; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); buf.p2(self.obj); buf.p2(self.scale); } + #[inline] fn test(&self) -> usize { return 6; } diff --git a/src/out/if_setplayerhead.rs b/src/out/if_setplayerhead.rs index d821863..bbc2d6c 100644 --- a/src/out/if_setplayerhead.rs +++ b/src/out/if_setplayerhead.rs @@ -8,6 +8,7 @@ pub struct IfSetPlayerHead { } impl IfSetPlayerHead { + #[inline] pub fn new( component: i32, ) -> IfSetPlayerHead { @@ -18,22 +19,27 @@ impl IfSetPlayerHead { } impl MessageEncoder for IfSetPlayerHead { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETPLAYERHEAD as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/if_setposition.rs b/src/out/if_setposition.rs index 5fb7b3a..07cddc5 100644 --- a/src/out/if_setposition.rs +++ b/src/out/if_setposition.rs @@ -10,6 +10,7 @@ pub struct IfSetPosition { } impl IfSetPosition { + #[inline] pub fn new( component: i32, x: i32, @@ -24,24 +25,29 @@ impl IfSetPosition { } impl MessageEncoder for IfSetPosition { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETPOSITION as i32; } + #[inline] fn length(&self) -> i32 { return 6; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); buf.p2(self.x); buf.p2(self.y); } + #[inline] fn test(&self) -> usize { return 6; } diff --git a/src/out/if_setrecol.rs b/src/out/if_setrecol.rs index 5eec1b9..f44d6b6 100644 --- a/src/out/if_setrecol.rs +++ b/src/out/if_setrecol.rs @@ -10,6 +10,7 @@ pub struct IfSetRecol { } impl IfSetRecol { + #[inline] pub fn new( component: i32, src: i32, @@ -24,24 +25,29 @@ impl IfSetRecol { } impl MessageEncoder for IfSetRecol { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETRECOL as i32; } + #[inline] fn length(&self) -> i32 { return 6; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); buf.p2(self.src); buf.p2(self.dst); } + #[inline] fn test(&self) -> usize { return 6; } diff --git a/src/out/if_settab.rs b/src/out/if_settab.rs index 24f918a..dd5fef3 100644 --- a/src/out/if_settab.rs +++ b/src/out/if_settab.rs @@ -9,6 +9,7 @@ pub struct IfSetTab { } impl IfSetTab { + #[inline] pub fn new( component: i32, tab: i32, @@ -21,23 +22,28 @@ impl IfSetTab { } impl MessageEncoder for IfSetTab { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETTAB as i32; } + #[inline] fn length(&self) -> i32 { return 3; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); buf.p1(self.tab); } + #[inline] fn test(&self) -> usize { return 3; } diff --git a/src/out/if_settabactive.rs b/src/out/if_settabactive.rs index 0f17219..4511244 100644 --- a/src/out/if_settabactive.rs +++ b/src/out/if_settabactive.rs @@ -8,6 +8,7 @@ pub struct IfSetTabActive { } impl IfSetTabActive { + #[inline] pub fn new( tab: i32, ) -> IfSetTabActive { @@ -18,22 +19,27 @@ impl IfSetTabActive { } impl MessageEncoder for IfSetTabActive { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETTAB_ACTIVE as i32; } + #[inline] fn length(&self) -> i32 { return 1; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.tab); } + #[inline] fn test(&self) -> usize { return 1; } diff --git a/src/out/if_settext.rs b/src/out/if_settext.rs index e00bd83..87b22b3 100644 --- a/src/out/if_settext.rs +++ b/src/out/if_settext.rs @@ -9,6 +9,7 @@ pub struct IfSetText { } impl IfSetText { + #[inline] pub fn new( component: i32, text: String, @@ -21,23 +22,28 @@ impl IfSetText { } impl MessageEncoder for IfSetText { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::IF_SETTEXT as i32; } + #[inline] fn length(&self) -> i32 { return -2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); buf.pjstr(&self.text, 10); } + #[inline] fn test(&self) -> usize { return 3 + self.text.len(); } diff --git a/src/out/last_login_info.rs b/src/out/last_login_info.rs index 966dcaf..c5998b3 100644 --- a/src/out/last_login_info.rs +++ b/src/out/last_login_info.rs @@ -11,6 +11,7 @@ pub struct LastLoginInfo { } impl LastLoginInfo { + #[inline] pub fn new( last_ip: i32, days_since_login: i32, @@ -27,18 +28,22 @@ impl LastLoginInfo { } impl MessageEncoder for LastLoginInfo { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::LAST_LOGIN_INFO as i32; } + #[inline] fn length(&self) -> i32 { return 9; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p4(self.last_ip); buf.p2(self.days_since_login); @@ -46,6 +51,7 @@ impl MessageEncoder for LastLoginInfo { buf.p2(self.messages); } + #[inline] fn test(&self) -> usize { return 9; } diff --git a/src/out/loc_addchange.rs b/src/out/loc_addchange.rs index acf269e..af9e373 100644 --- a/src/out/loc_addchange.rs +++ b/src/out/loc_addchange.rs @@ -11,6 +11,7 @@ pub struct LocAddChange { } impl LocAddChange { + #[inline] pub fn new( coord: i32, loc: i32, @@ -27,24 +28,29 @@ impl LocAddChange { } impl MessageEncoder for LocAddChange { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::LOC_ADD_CHANGE as i32; } + #[inline] fn length(&self) -> i32 { return 4; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); buf.p1((self.shape << 2) | (self.angle & 0x3)); buf.p2(self.loc); } + #[inline] fn test(&self) -> usize { return 4; } diff --git a/src/out/loc_anim.rs b/src/out/loc_anim.rs index 7478f05..7024177 100644 --- a/src/out/loc_anim.rs +++ b/src/out/loc_anim.rs @@ -11,6 +11,7 @@ pub struct LocAnim { } impl LocAnim { + #[inline] pub fn new( coord: i32, shape: i32, @@ -27,24 +28,29 @@ impl LocAnim { } impl MessageEncoder for LocAnim { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::LOC_ANIM as i32; } + #[inline] fn length(&self) -> i32 { return 4; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); buf.p1((self.shape << 2) | (self.angle & 0x3)); buf.p2(self.seq); } + #[inline] fn test(&self) -> usize { return 4; } diff --git a/src/out/loc_del.rs b/src/out/loc_del.rs index 03c27be..a455dc4 100644 --- a/src/out/loc_del.rs +++ b/src/out/loc_del.rs @@ -10,6 +10,7 @@ pub struct LocDel { } impl LocDel { + #[inline] pub fn new( coord: i32, shape: i32, @@ -24,23 +25,28 @@ impl LocDel { } impl MessageEncoder for LocDel { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::LOC_DEL as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); buf.p1((self.shape << 2) | (self.angle & 0x3)); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/loc_merge.rs b/src/out/loc_merge.rs index 3448f6c..79d3160 100644 --- a/src/out/loc_merge.rs +++ b/src/out/loc_merge.rs @@ -21,6 +21,7 @@ pub struct LocMerge { } impl LocMerge { + #[inline] pub fn new( src_x: i32, src_z: i32, @@ -54,17 +55,21 @@ impl LocMerge { } impl MessageEncoder for LocMerge { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::LOC_MERGE as i32; } + #[inline] fn length(&self) -> i32 { return 14; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); @@ -79,6 +84,7 @@ impl MessageEncoder for LocMerge { buf.p1(self.north - self.src_z); } + #[inline] fn test(&self) -> usize { return 14; } diff --git a/src/out/logout.rs b/src/out/logout.rs index 90d0d7a..c3f3b60 100644 --- a/src/out/logout.rs +++ b/src/out/logout.rs @@ -6,26 +6,32 @@ use crate::prot::ServerInternalProt; pub struct Logout {} impl Logout { + #[inline] pub fn new() -> Logout { return Logout {} } } impl MessageEncoder for Logout { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::LOGOUT as i32; } + #[inline] fn length(&self) -> i32 { return 0; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, _: &mut Packet) {} + #[inline] fn test(&self) -> usize { return 0; } diff --git a/src/out/map_anim.rs b/src/out/map_anim.rs index c4d459e..9b457a2 100644 --- a/src/out/map_anim.rs +++ b/src/out/map_anim.rs @@ -11,6 +11,7 @@ pub struct MapAnim { } impl MapAnim { + #[inline] pub fn new( coord: i32, spotanim: i32, @@ -27,18 +28,22 @@ impl MapAnim { } impl MessageEncoder for MapAnim { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::MAP_ANIM as i32; } + #[inline] fn length(&self) -> i32 { return 6; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); buf.p2(self.spotanim); @@ -46,6 +51,7 @@ impl MessageEncoder for MapAnim { buf.p2(self.delay); } + #[inline] fn test(&self) -> usize { return 6; } diff --git a/src/out/map_projanim.rs b/src/out/map_projanim.rs index 8af0dee..8622165 100644 --- a/src/out/map_projanim.rs +++ b/src/out/map_projanim.rs @@ -21,6 +21,7 @@ pub struct MapProjAnim { } impl MapProjAnim { + #[inline] pub fn new( src_x: i32, src_z: i32, @@ -54,18 +55,22 @@ impl MapProjAnim { } impl MessageEncoder for MapProjAnim { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::MAP_PROJANIM as i32; } + #[inline] fn length(&self) -> i32 { return 15; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); buf.p1(self.dst_x - self.src_x); @@ -80,6 +85,7 @@ impl MessageEncoder for MapProjAnim { buf.p1(self.arc); } + #[inline] fn test(&self) -> usize { return 15; } diff --git a/src/out/message_game.rs b/src/out/message_game.rs index 8176452..e10c564 100644 --- a/src/out/message_game.rs +++ b/src/out/message_game.rs @@ -8,6 +8,7 @@ pub struct MessageGame { } impl MessageGame { + #[inline] pub fn new(msg: String) -> MessageGame { return MessageGame { msg, @@ -16,22 +17,27 @@ impl MessageGame { } impl MessageEncoder for MessageGame { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::MESSAGE_GAME as i32 } + #[inline] fn length(&self) -> i32 { return -1; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.pjstr(&self.msg, 10); } + #[inline] fn test(&self) -> usize { return 1 + self.msg.len(); } diff --git a/src/out/message_private.rs b/src/out/message_private.rs index 25315f8..3ab0a0b 100644 --- a/src/out/message_private.rs +++ b/src/out/message_private.rs @@ -12,6 +12,7 @@ pub struct MessagePrivateOut { } impl MessagePrivateOut { + #[inline] pub fn new( from: i64, id: i32, @@ -28,18 +29,22 @@ impl MessagePrivateOut { } impl MessageEncoder for MessagePrivateOut { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::MESSAGE_PRIVATE as i32 } + #[inline] fn length(&self) -> i32 { return -1; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { let mut staff_mod_level = self.staff_mod_level; if staff_mod_level > 0 { @@ -52,6 +57,7 @@ impl MessageEncoder for MessagePrivateOut { unsafe { WordPack::pack(buf, self.msg.clone()); } } + #[inline] fn test(&self) -> usize { return 14 + self.msg.len(); } diff --git a/src/out/midi_jingle.rs b/src/out/midi_jingle.rs index 1b2f647..b64177c 100644 --- a/src/out/midi_jingle.rs +++ b/src/out/midi_jingle.rs @@ -9,6 +9,7 @@ pub struct MidiJingle { } impl MidiJingle { + #[inline] pub fn new( delay: i32, data: Vec, @@ -21,23 +22,28 @@ impl MidiJingle { } impl MessageEncoder for MidiJingle { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::MIDI_JINGLE as i32; } + #[inline] fn length(&self) -> i32 { return -2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.delay); buf.pdata(&self.data, 0, self.data.len()); } + #[inline] fn test(&self) -> usize { return 6 + self.data.len(); } diff --git a/src/out/midi_song.rs b/src/out/midi_song.rs index 379f598..cd2f495 100644 --- a/src/out/midi_song.rs +++ b/src/out/midi_song.rs @@ -10,6 +10,7 @@ pub struct MidiSong { } impl MidiSong { + #[inline] pub fn new( name: String, crc: i32, @@ -24,24 +25,29 @@ impl MidiSong { } impl MessageEncoder for MidiSong { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::MIDI_SONG as i32; } + #[inline] fn length(&self) -> i32 { return -1; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.pjstr(&self.name, 10); buf.p4(self.crc); buf.p4(self.length); } + #[inline] fn test(&self) -> usize { return 9 + self.name.len(); } diff --git a/src/out/obj_add.rs b/src/out/obj_add.rs index 1863ed2..f1f50d1 100644 --- a/src/out/obj_add.rs +++ b/src/out/obj_add.rs @@ -10,6 +10,7 @@ pub struct ObjAdd { } impl ObjAdd { + #[inline] pub fn new( coord: i32, obj: i32, @@ -24,24 +25,29 @@ impl ObjAdd { } impl MessageEncoder for ObjAdd { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::OBJ_ADD as i32; } + #[inline] fn length(&self) -> i32 { return 5; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); buf.p2(self.obj); buf.p2(self.count.min(65535)); } + #[inline] fn test(&self) -> usize { return 5; } diff --git a/src/out/obj_count.rs b/src/out/obj_count.rs index 83aa7fb..7471683 100644 --- a/src/out/obj_count.rs +++ b/src/out/obj_count.rs @@ -11,6 +11,7 @@ pub struct ObjCount { } impl ObjCount { + #[inline] pub fn new( coord: i32, obj: i32, @@ -27,18 +28,22 @@ impl ObjCount { } impl MessageEncoder for ObjCount { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::OBJ_COUNT as i32; } + #[inline] fn length(&self) -> i32 { return 7; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); buf.p2(self.obj); @@ -46,6 +51,7 @@ impl MessageEncoder for ObjCount { buf.p2(self.new_count.min(65535)); } + #[inline] fn test(&self) -> usize { return 7; } diff --git a/src/out/obj_del.rs b/src/out/obj_del.rs index 54d588a..e241ff0 100644 --- a/src/out/obj_del.rs +++ b/src/out/obj_del.rs @@ -9,6 +9,7 @@ pub struct ObjDel { } impl ObjDel { + #[inline] pub fn new( coord: i32, obj: i32, @@ -21,23 +22,28 @@ impl ObjDel { } impl MessageEncoder for ObjDel { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::OBJ_DEL as i32; } + #[inline] fn length(&self) -> i32 { return 3; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); buf.p2(self.obj); } + #[inline] fn test(&self) -> usize { return 3; } diff --git a/src/out/obj_reveal.rs b/src/out/obj_reveal.rs index 1586aa4..4d7aa11 100644 --- a/src/out/obj_reveal.rs +++ b/src/out/obj_reveal.rs @@ -11,6 +11,7 @@ pub struct ObjReveal { } impl ObjReveal { + #[inline] pub fn new( coord: i32, obj: i32, @@ -27,18 +28,22 @@ impl ObjReveal { } impl MessageEncoder for ObjReveal { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::OBJ_REVEAL as i32; } + #[inline] fn length(&self) -> i32 { return 7; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); buf.p2(self.obj); @@ -46,6 +51,7 @@ impl MessageEncoder for ObjReveal { buf.p2(self.receiver); } + #[inline] fn test(&self) -> usize { return 7; } diff --git a/src/out/rebuild_normal.rs b/src/out/rebuild_normal.rs index b43d9b6..c0bb62b 100644 --- a/src/out/rebuild_normal.rs +++ b/src/out/rebuild_normal.rs @@ -12,6 +12,7 @@ pub struct RebuildNormal { } impl RebuildNormal { + #[inline] pub fn new( x: i32, z: i32, @@ -30,18 +31,22 @@ impl RebuildNormal { } impl MessageEncoder for RebuildNormal { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::REBUILD_NORMAL as i32; } + #[inline] fn length(&self) -> i32 { return -2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.x); buf.p2(self.z); @@ -52,15 +57,9 @@ impl MessageEncoder for RebuildNormal { buf.p4(unsafe { *self.maps.as_ptr().add(index) }); buf.p4(unsafe { *self.locs.as_ptr().add(index) }); } - // for &packed in self.squares.iter() { - // // buf.p1(((packed >> 72) & 0xff) as i32); - // // buf.p1(((packed >> 64) & 0xff) as i32); - // // buf.p4(((packed >> 32) & 0xffffffff) as i32); - // // buf.p4((packed & 0xffffffff) as i32); - // // (50n << 72n) + (50n << 64n) + (BigInt.asUintN(32, -2147483648n) << 32n) + 2147483647n - // } } + #[inline] fn test(&self) -> usize { return 2 + 2 + self.squares.len() * (1 + 1 + 4 + 4); } diff --git a/src/out/reset_anims.rs b/src/out/reset_anims.rs index 2227ea8..f94a3d9 100644 --- a/src/out/reset_anims.rs +++ b/src/out/reset_anims.rs @@ -6,26 +6,32 @@ use crate::prot::ServerInternalProt; pub struct ResetAnims {} impl ResetAnims { + #[inline] pub fn new() -> ResetAnims { return ResetAnims {} } } impl MessageEncoder for ResetAnims { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::RESET_ANIMS as i32; } + #[inline] fn length(&self) -> i32 { return 0; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; // todo: what should priority be? } + #[inline] fn encode(&self, _: &mut Packet) {} + #[inline] fn test(&self) -> usize { return 0; } diff --git a/src/out/reset_clientvarcache.rs b/src/out/reset_clientvarcache.rs index 9d8f0d0..a626aa0 100644 --- a/src/out/reset_clientvarcache.rs +++ b/src/out/reset_clientvarcache.rs @@ -6,26 +6,32 @@ use crate::prot::ServerInternalProt; pub struct ResetClientVarCache {} impl ResetClientVarCache { + #[inline] pub fn new() -> ResetClientVarCache { return ResetClientVarCache {} } } impl MessageEncoder for ResetClientVarCache { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::RESET_CLIENT_VARCACHE as i32; } + #[inline] fn length(&self) -> i32 { return 0; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, _: &mut Packet) {} + #[inline] fn test(&self) -> usize { return 0; } diff --git a/src/out/set_multiway.rs b/src/out/set_multiway.rs index 510bf94..bf8878f 100644 --- a/src/out/set_multiway.rs +++ b/src/out/set_multiway.rs @@ -8,6 +8,7 @@ pub struct SetMultiway { } impl SetMultiway { + #[inline] pub fn new(hidden: bool) -> SetMultiway { return SetMultiway { hidden, @@ -16,22 +17,27 @@ impl SetMultiway { } impl MessageEncoder for SetMultiway { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::SET_MULTIWAY as i32; } + #[inline] fn length(&self) -> i32 { return 1; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(if self.hidden { 1 } else { 0 }); } + #[inline] fn test(&self) -> usize { return 1; } diff --git a/src/out/synth_sound.rs b/src/out/synth_sound.rs index 223dcce..7df68e4 100644 --- a/src/out/synth_sound.rs +++ b/src/out/synth_sound.rs @@ -10,6 +10,7 @@ pub struct SynthSound { } impl SynthSound { + #[inline] pub fn new( synth: i32, loops: i32, @@ -24,24 +25,29 @@ impl SynthSound { } impl MessageEncoder for SynthSound { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::SYNTH_SOUND as i32; } + #[inline] fn length(&self) -> i32 { return 5; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.synth); buf.p1(self.loops); buf.p2(self.delay); } + #[inline] fn test(&self) -> usize { return 5; } diff --git a/src/out/tut_flash.rs b/src/out/tut_flash.rs index 36fc337..9e30979 100644 --- a/src/out/tut_flash.rs +++ b/src/out/tut_flash.rs @@ -8,6 +8,7 @@ pub struct TutFlash { } impl TutFlash { + #[inline] pub fn new( tab: i32, ) -> TutFlash { @@ -18,22 +19,27 @@ impl TutFlash { } impl MessageEncoder for TutFlash { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::TUT_FLASH as i32; } + #[inline] fn length(&self) -> i32 { return 1; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.tab); } + #[inline] fn test(&self) -> usize { return 1; } diff --git a/src/out/tut_open.rs b/src/out/tut_open.rs index 151b9f4..de19378 100644 --- a/src/out/tut_open.rs +++ b/src/out/tut_open.rs @@ -8,6 +8,7 @@ pub struct TutOpen { } impl TutOpen { + #[inline] pub fn new( component: i32, ) -> TutOpen { @@ -18,22 +19,27 @@ impl TutOpen { } impl MessageEncoder for TutOpen { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::TUT_OPEN as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/unset_map_flag.rs b/src/out/unset_map_flag.rs index 6517fbe..c390936 100644 --- a/src/out/unset_map_flag.rs +++ b/src/out/unset_map_flag.rs @@ -6,26 +6,32 @@ use crate::prot::ServerInternalProt; pub struct UnsetMapFlag {} impl UnsetMapFlag { + #[inline] pub fn new() -> UnsetMapFlag { return UnsetMapFlag {} } } impl MessageEncoder for UnsetMapFlag { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UNSET_MAP_FLAG as i32; } + #[inline] fn length(&self) -> i32 { return 0; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, _: &mut Packet) {} + #[inline] fn test(&self) -> usize { return 0; } diff --git a/src/out/update_friendlist.rs b/src/out/update_friendlist.rs index f18252c..036df80 100644 --- a/src/out/update_friendlist.rs +++ b/src/out/update_friendlist.rs @@ -9,6 +9,7 @@ pub struct UpdateFriendList { } impl UpdateFriendList { + #[inline] pub fn new(name: i64, node: i32) -> UpdateFriendList { return UpdateFriendList { name, @@ -18,23 +19,28 @@ impl UpdateFriendList { } impl MessageEncoder for UpdateFriendList { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_FRIENDLIST as i32; } + #[inline] fn length(&self) -> i32 { return 9; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p8(self.name); buf.p1(self.node); } + #[inline] fn test(&self) -> usize { return 9; } diff --git a/src/out/update_ignorelist.rs b/src/out/update_ignorelist.rs index 770fa3e..1ded27d 100644 --- a/src/out/update_ignorelist.rs +++ b/src/out/update_ignorelist.rs @@ -8,6 +8,7 @@ pub struct UpdateIgnoreList { } impl UpdateIgnoreList { + #[inline] pub fn new(names: Vec) -> UpdateIgnoreList { return UpdateIgnoreList { names, @@ -16,24 +17,29 @@ impl UpdateIgnoreList { } impl MessageEncoder for UpdateIgnoreList { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_IGNORELIST as i32; } + #[inline] fn length(&self) -> i32 { return -2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { for &name in self.names.iter() { buf.p8(name); } } + #[inline] fn test(&self) -> usize { return 8 * self.names.len(); } diff --git a/src/out/update_inv_full.rs b/src/out/update_inv_full.rs index 0033788..6a2ef27 100644 --- a/src/out/update_inv_full.rs +++ b/src/out/update_inv_full.rs @@ -10,6 +10,7 @@ pub struct UpdateInvFull { } impl UpdateInvFull { + #[inline] pub fn new( size: i32, component: i32, @@ -24,18 +25,22 @@ impl UpdateInvFull { } impl MessageEncoder for UpdateInvFull { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_INV_FULL as i32; } + #[inline] fn length(&self) -> i32 { return -2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { // todo: size should be the index of the last non-empty slot buf.p2(self.component); @@ -59,6 +64,7 @@ impl MessageEncoder for UpdateInvFull { } } + #[inline] fn test(&self) -> usize { let mut length: usize = 0; length += 3; diff --git a/src/out/update_inv_partial.rs b/src/out/update_inv_partial.rs index 5b51546..9235276 100644 --- a/src/out/update_inv_partial.rs +++ b/src/out/update_inv_partial.rs @@ -10,6 +10,7 @@ pub struct UpdateInvPartial { } impl UpdateInvPartial { + #[inline] pub fn new( component: i32, slots: Vec, @@ -24,18 +25,22 @@ impl UpdateInvPartial { } impl MessageEncoder for UpdateInvPartial { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_INV_PARTIAL as i32; } + #[inline] fn length(&self) -> i32 { return -2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { // todo: size should be the index of the last non-empty slot buf.p2(self.component); @@ -59,6 +64,7 @@ impl MessageEncoder for UpdateInvPartial { } } + #[inline] fn test(&self) -> usize { let mut length: usize = 0; length += 2; diff --git a/src/out/update_inv_stop_transmit.rs b/src/out/update_inv_stop_transmit.rs index b73f180..4b66d97 100644 --- a/src/out/update_inv_stop_transmit.rs +++ b/src/out/update_inv_stop_transmit.rs @@ -8,6 +8,7 @@ pub struct UpdateInvStopTransmit { } impl UpdateInvStopTransmit { + #[inline] pub fn new( component: i32, ) -> UpdateInvStopTransmit { @@ -18,22 +19,27 @@ impl UpdateInvStopTransmit { } impl MessageEncoder for UpdateInvStopTransmit { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_INV_STOP_TRANSMIT as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/update_pid.rs b/src/out/update_pid.rs index faf5285..d335938 100644 --- a/src/out/update_pid.rs +++ b/src/out/update_pid.rs @@ -8,6 +8,7 @@ pub struct UpdatePid { } impl UpdatePid { + #[inline] pub fn new( pid: i32, ) -> UpdatePid { @@ -18,22 +19,27 @@ impl UpdatePid { } impl MessageEncoder for UpdatePid { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_PID as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; // todo: what should priority be? } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.pid); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/update_reboot_timer.rs b/src/out/update_reboot_timer.rs index e3d7733..8a61c39 100644 --- a/src/out/update_reboot_timer.rs +++ b/src/out/update_reboot_timer.rs @@ -8,6 +8,7 @@ pub struct UpdateRebootTimer { } impl UpdateRebootTimer { + #[inline] pub fn new( ticks: i32, ) -> UpdateRebootTimer { @@ -18,22 +19,27 @@ impl UpdateRebootTimer { } impl MessageEncoder for UpdateRebootTimer { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_REBOOT_TIMER as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; // todo: what should priority be? } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.ticks); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/update_runenergy.rs b/src/out/update_runenergy.rs index 4251702..941e609 100644 --- a/src/out/update_runenergy.rs +++ b/src/out/update_runenergy.rs @@ -8,6 +8,7 @@ pub struct UpdateRunEnergy { } impl UpdateRunEnergy { + #[inline] pub fn new( energy: i32, ) -> UpdateRunEnergy { @@ -18,22 +19,27 @@ impl UpdateRunEnergy { } impl MessageEncoder for UpdateRunEnergy { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_RUNENERGY as i32; } + #[inline] fn length(&self) -> i32 { return 1; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.energy / 100); } + #[inline] fn test(&self) -> usize { return 1; } diff --git a/src/out/update_runweight.rs b/src/out/update_runweight.rs index 56a8f20..3200a49 100644 --- a/src/out/update_runweight.rs +++ b/src/out/update_runweight.rs @@ -8,6 +8,7 @@ pub struct UpdateRunWeight { } impl UpdateRunWeight { + #[inline] pub fn new( kg: i32, ) -> UpdateRunWeight { @@ -18,22 +19,27 @@ impl UpdateRunWeight { } impl MessageEncoder for UpdateRunWeight { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_RUNWEIGHT as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.kg); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/update_stat.rs b/src/out/update_stat.rs index 1be53be..4889c9c 100644 --- a/src/out/update_stat.rs +++ b/src/out/update_stat.rs @@ -10,6 +10,7 @@ pub struct UpdateStat { } impl UpdateStat { + #[inline] pub fn new( stat: i32, experience: i32, @@ -24,24 +25,29 @@ impl UpdateStat { } impl MessageEncoder for UpdateStat { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_STAT as i32; } + #[inline] fn length(&self) -> i32 { return 6; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Buffered; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.stat); buf.p4(self.experience / 10); buf.p1(self.level); // not base level } + #[inline] fn test(&self) -> usize { return 6; } diff --git a/src/out/update_zone_full_follows.rs b/src/out/update_zone_full_follows.rs index 63fcc91..30f4cfa 100644 --- a/src/out/update_zone_full_follows.rs +++ b/src/out/update_zone_full_follows.rs @@ -12,6 +12,7 @@ pub struct UpdateZoneFullFollows { } impl UpdateZoneFullFollows { + #[inline] pub fn new( x: i32, z: i32, @@ -28,23 +29,28 @@ impl UpdateZoneFullFollows { } impl MessageEncoder for UpdateZoneFullFollows { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_ZONE_FULL_FOLLOWS as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1((self.x << 3) - CoordGrid::origin(self.origin_x as u16) as i32); buf.p1((self.z << 3) - CoordGrid::origin(self.origin_z as u16) as i32); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/update_zone_partial_enclosed.rs b/src/out/update_zone_partial_enclosed.rs index 787490b..efc767e 100644 --- a/src/out/update_zone_partial_enclosed.rs +++ b/src/out/update_zone_partial_enclosed.rs @@ -13,6 +13,7 @@ pub struct UpdateZonePartialEnclosed { } impl UpdateZonePartialEnclosed { + #[inline] pub fn new( x: i32, z: i32, @@ -31,24 +32,29 @@ impl UpdateZonePartialEnclosed { } impl MessageEncoder for UpdateZonePartialEnclosed { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_ZONE_PARTIAL_ENCLOSED as i32; } + #[inline] fn length(&self) -> i32 { return -2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1((self.x << 3) - CoordGrid::origin(self.origin_x as u16) as i32); buf.p1((self.z << 3) - CoordGrid::origin(self.origin_z as u16) as i32); buf.pdata(&self.data, 0, self.data.len()); } + #[inline] fn test(&self) -> usize { return 2 + self.data.len(); } diff --git a/src/out/update_zone_partial_follows.rs b/src/out/update_zone_partial_follows.rs index 37bdb7d..4b81d21 100644 --- a/src/out/update_zone_partial_follows.rs +++ b/src/out/update_zone_partial_follows.rs @@ -12,6 +12,7 @@ pub struct UpdateZonePartialFollows { } impl UpdateZonePartialFollows { + #[inline] pub fn new( x: i32, z: i32, @@ -28,23 +29,28 @@ impl UpdateZonePartialFollows { } impl MessageEncoder for UpdateZonePartialFollows { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::UPDATE_ZONE_PARTIAL_FOLLOWS as i32; } + #[inline] fn length(&self) -> i32 { return 2; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p1((self.x << 3) - CoordGrid::origin(self.origin_x as u16) as i32); buf.p1((self.z << 3) - CoordGrid::origin(self.origin_z as u16) as i32); } + #[inline] fn test(&self) -> usize { return 2; } diff --git a/src/out/varp_large.rs b/src/out/varp_large.rs index d9a25db..d7cb08b 100644 --- a/src/out/varp_large.rs +++ b/src/out/varp_large.rs @@ -9,6 +9,7 @@ pub struct VarpLarge { } impl VarpLarge { + #[inline] pub fn new( varp: i32, value: i32, @@ -21,23 +22,28 @@ impl VarpLarge { } impl MessageEncoder for VarpLarge { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::VARP_LARGE as i32; } + #[inline] fn length(&self) -> i32 { return 6; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.varp); buf.p4(self.value); } + #[inline] fn test(&self) -> usize { return 6; } diff --git a/src/out/varp_small.rs b/src/out/varp_small.rs index 752ea17..8b0e4be 100644 --- a/src/out/varp_small.rs +++ b/src/out/varp_small.rs @@ -9,6 +9,7 @@ pub struct VarpSmall { } impl VarpSmall { + #[inline] pub fn new( varp: i32, value: i32, @@ -21,23 +22,28 @@ impl VarpSmall { } impl MessageEncoder for VarpSmall { + #[inline] fn id(&self) -> i32 { return ServerInternalProt::VARP_SMALL as i32; } + #[inline] fn length(&self) -> i32 { return 3; } + #[inline] fn priority(&self) -> ServerProtPriority { return ServerProtPriority::Immediate; } + #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.varp); buf.p1(self.value); } + #[inline] fn test(&self) -> usize { return 3; } diff --git a/src/pack.rs b/src/pack.rs index 07605a0..b2e02b9 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -12,6 +12,7 @@ impl WordPack { '&', '*', '\\', '\'', '@', '#', '+', '=', '£', '$', '%', '"', '[', ']' ]; + #[inline] pub unsafe fn unpack(packet: &mut Packet, length: usize) -> String { let mut char_buffer: Vec = Vec::with_capacity(80); let mut pos: usize = 0; @@ -59,6 +60,7 @@ impl WordPack { WordPack::sentence_case(&char_buffer.get_unchecked(..pos).iter().collect::()) } + #[inline] pub unsafe fn pack(packet: &mut Packet, mut input: String) { if input.len() > 80 { input.truncate(80); @@ -99,6 +101,7 @@ impl WordPack { } } + #[inline] pub fn sentence_case(input: &str) -> String { let mut chars: Vec = input.to_lowercase().chars().collect(); let mut punctuation: bool = true; From 6efad0dd4cfaea360bac388b5615113912022eae Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 31 Mar 2025 12:27:41 -0400 Subject: [PATCH 05/14] feat: performance and memory copy optimizations --- src/in/anticheat.rs | 30 +- src/in/chat_setmode.rs | 2 +- src/in/client_cheat.rs | 2 +- src/in/close_modal.rs | 2 +- src/in/event.rs | 4 +- src/in/friend.rs | 4 +- src/in/idle_timer.rs | 2 +- src/in/if_button.rs | 2 +- src/in/if_playerdesign.rs | 2 +- src/in/ignore.rs | 4 +- src/in/inv_button.rs | 4 +- src/in/message_private.rs | 2 +- src/in/message_public.rs | 2 +- src/in/move_click.rs | 2 +- src/in/no_timeout.rs | 2 +- src/in/opheld.rs | 6 +- src/in/oploc.rs | 6 +- src/in/opnpc.rs | 6 +- src/in/opobj.rs | 6 +- src/in/opplayer.rs | 6 +- src/in/rebuild_getmaps.rs | 2 +- src/in/reportabuse.rs | 2 +- src/in/resume_countdialog.rs | 2 +- src/in/resume_pausebutton.rs | 2 +- src/in/tutorial_clickside.rs | 2 +- src/lib.rs | 1304 ++++++++++++++-------------------- src/message.rs | 60 +- src/out/message_private.rs | 3 +- src/pack.rs | 27 +- src/player.rs | 52 +- 30 files changed, 665 insertions(+), 887 deletions(-) diff --git a/src/in/anticheat.rs b/src/in/anticheat.rs index 7c7bcc1..7cb9ed3 100644 --- a/src/in/anticheat.rs +++ b/src/in/anticheat.rs @@ -22,7 +22,7 @@ impl MessageDecoder for AnticheatOp1 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp1 { + fn decode(_: ClientProt, _: Packet) -> AnticheatOp1 { return AnticheatOp1::new(); } } @@ -48,7 +48,7 @@ impl MessageDecoder for AnticheatOp2 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp2 { + fn decode(_: ClientProt, _: Packet) -> AnticheatOp2 { return AnticheatOp2::new(); } } @@ -74,7 +74,7 @@ impl MessageDecoder for AnticheatOp3 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp3 { + fn decode(_: ClientProt, _: Packet) -> AnticheatOp3 { return AnticheatOp3::new(); } } @@ -100,7 +100,7 @@ impl MessageDecoder for AnticheatOp4 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp4 { + fn decode(_: ClientProt, _: Packet) -> AnticheatOp4 { return AnticheatOp4::new(); } } @@ -126,7 +126,7 @@ impl MessageDecoder for AnticheatOp5 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp5 { + fn decode(_: ClientProt, _: Packet) -> AnticheatOp5 { return AnticheatOp5::new(); } } @@ -152,7 +152,7 @@ impl MessageDecoder for AnticheatOp6 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp6 { + fn decode(_: ClientProt, _: Packet) -> AnticheatOp6 { return AnticheatOp6::new(); } } @@ -178,7 +178,7 @@ impl MessageDecoder for AnticheatOp7 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp7 { + fn decode(_: ClientProt, _: Packet) -> AnticheatOp7 { return AnticheatOp7::new(); } } @@ -204,7 +204,7 @@ impl MessageDecoder for AnticheatOp8 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp8 { + fn decode(_: ClientProt, _: Packet) -> AnticheatOp8 { return AnticheatOp8::new(); } } @@ -230,7 +230,7 @@ impl MessageDecoder for AnticheatOp9 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatOp9 { + fn decode(_: ClientProt, _: Packet) -> AnticheatOp9 { return AnticheatOp9::new(); } } @@ -256,7 +256,7 @@ impl MessageDecoder for AnticheatCycle1 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle1 { + fn decode(_: ClientProt, _: Packet) -> AnticheatCycle1 { return AnticheatCycle1::new(); } } @@ -282,7 +282,7 @@ impl MessageDecoder for AnticheatCycle2 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle2 { + fn decode(_: ClientProt, _: Packet) -> AnticheatCycle2 { return AnticheatCycle2::new(); } } @@ -308,7 +308,7 @@ impl MessageDecoder for AnticheatCycle3 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle3 { + fn decode(_: ClientProt, _: Packet) -> AnticheatCycle3 { return AnticheatCycle3::new(); } } @@ -334,7 +334,7 @@ impl MessageDecoder for AnticheatCycle4 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle4 { + fn decode(_: ClientProt, _: Packet) -> AnticheatCycle4 { return AnticheatCycle4::new(); } } @@ -360,7 +360,7 @@ impl MessageDecoder for AnticheatCycle5 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle5 { + fn decode(_: ClientProt, _: Packet) -> AnticheatCycle5 { return AnticheatCycle5::new(); } } @@ -386,7 +386,7 @@ impl MessageDecoder for AnticheatCycle6 { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> AnticheatCycle6 { + fn decode(_: ClientProt, _: Packet) -> AnticheatCycle6 { return AnticheatCycle6::new(); } } \ No newline at end of file diff --git a/src/in/chat_setmode.rs b/src/in/chat_setmode.rs index 6a58818..faf5771 100644 --- a/src/in/chat_setmode.rs +++ b/src/in/chat_setmode.rs @@ -37,7 +37,7 @@ impl MessageDecoder for ChatSetMode { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> ChatSetMode { + fn decode(_: ClientProt, mut buf: Packet) -> ChatSetMode { return ChatSetMode::new( buf.g1(), buf.g1(), diff --git a/src/in/client_cheat.rs b/src/in/client_cheat.rs index 61e86ec..8a380ab 100644 --- a/src/in/client_cheat.rs +++ b/src/in/client_cheat.rs @@ -27,7 +27,7 @@ impl MessageDecoder for ClientCheat { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> ClientCheat { + fn decode(_: ClientProt, mut buf: Packet) -> ClientCheat { return ClientCheat::new(buf.gjstr(10)); } } \ No newline at end of file diff --git a/src/in/close_modal.rs b/src/in/close_modal.rs index 7ddc540..a1cf2d8 100644 --- a/src/in/close_modal.rs +++ b/src/in/close_modal.rs @@ -22,7 +22,7 @@ impl MessageDecoder for CloseModal { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> CloseModal { + fn decode(_: ClientProt, _: Packet) -> CloseModal { return CloseModal::new(); } } \ No newline at end of file diff --git a/src/in/event.rs b/src/in/event.rs index 214baff..41cb196 100644 --- a/src/in/event.rs +++ b/src/in/event.rs @@ -27,7 +27,7 @@ impl MessageDecoder for EventTracking { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> EventTracking { + fn decode(_: ClientProt, buf: Packet) -> EventTracking { return EventTracking::new(buf.data.clone()); } } @@ -72,7 +72,7 @@ impl MessageDecoder for EventCameraPosition { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> EventCameraPosition { + fn decode(_: ClientProt, mut buf: Packet) -> EventCameraPosition { return EventCameraPosition::new( buf.g2() as i32, buf.g2() as i32, diff --git a/src/in/friend.rs b/src/in/friend.rs index 39b6e4c..7bb76cb 100644 --- a/src/in/friend.rs +++ b/src/in/friend.rs @@ -27,7 +27,7 @@ impl MessageDecoder for FriendListAdd { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> FriendListAdd { + fn decode(_: ClientProt, mut buf: Packet) -> FriendListAdd { return FriendListAdd::new(buf.g8s()); } } @@ -58,7 +58,7 @@ impl MessageDecoder for FriendListDel { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> FriendListDel { + fn decode(_: ClientProt, mut buf: Packet) -> FriendListDel { return FriendListDel::new(buf.g8s()); } } \ No newline at end of file diff --git a/src/in/idle_timer.rs b/src/in/idle_timer.rs index ddf02b8..8346f35 100644 --- a/src/in/idle_timer.rs +++ b/src/in/idle_timer.rs @@ -22,7 +22,7 @@ impl MessageDecoder for IdleTimer { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> IdleTimer { + fn decode(_: ClientProt, _: Packet) -> IdleTimer { return IdleTimer::new(); } } \ No newline at end of file diff --git a/src/in/if_button.rs b/src/in/if_button.rs index 8d2c61c..39f09b6 100644 --- a/src/in/if_button.rs +++ b/src/in/if_button.rs @@ -27,7 +27,7 @@ impl MessageDecoder for IfButton { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> IfButton { + fn decode(_: ClientProt, mut buf: Packet) -> IfButton { return IfButton::new(buf.g2()); } } \ No newline at end of file diff --git a/src/in/if_playerdesign.rs b/src/in/if_playerdesign.rs index 05b71fe..e2388b2 100644 --- a/src/in/if_playerdesign.rs +++ b/src/in/if_playerdesign.rs @@ -37,7 +37,7 @@ impl MessageDecoder for IfPlayerDesign { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> IfPlayerDesign { + fn decode(_: ClientProt, mut buf: Packet) -> IfPlayerDesign { let gender: u8 = buf.g1(); let mut idkit: [i32; 7] = [0; 7]; diff --git a/src/in/ignore.rs b/src/in/ignore.rs index e1dda2d..629bf1d 100644 --- a/src/in/ignore.rs +++ b/src/in/ignore.rs @@ -27,7 +27,7 @@ impl MessageDecoder for IgnoreListAdd { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> IgnoreListAdd { + fn decode(_: ClientProt, mut buf: Packet) -> IgnoreListAdd { return IgnoreListAdd::new(buf.g8s()); } } @@ -58,7 +58,7 @@ impl MessageDecoder for IgnoreListDel { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> IgnoreListDel { + fn decode(_: ClientProt, mut buf: Packet) -> IgnoreListDel { return IgnoreListDel::new(buf.g8s()); } } \ No newline at end of file diff --git a/src/in/inv_button.rs b/src/in/inv_button.rs index f17dde8..7c30d96 100644 --- a/src/in/inv_button.rs +++ b/src/in/inv_button.rs @@ -41,7 +41,7 @@ impl MessageDecoder for InvButton { } #[inline] - fn decode(prot: ClientProt, buf: &mut Packet) -> InvButton { + fn decode(prot: ClientProt, mut buf: Packet) -> InvButton { let op: u8 = match prot { ClientProt::INV_BUTTON1 => 1, ClientProt::INV_BUTTON2 => 2, @@ -95,7 +95,7 @@ impl MessageDecoder for InvButtonD { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> InvButtonD { + fn decode(_: ClientProt, mut buf: Packet) -> InvButtonD { return InvButtonD::new( buf.g2(), buf.g2(), diff --git a/src/in/message_private.rs b/src/in/message_private.rs index 0a5fbd4..1db77fc 100644 --- a/src/in/message_private.rs +++ b/src/in/message_private.rs @@ -33,7 +33,7 @@ impl MessageDecoder for MessagePrivate { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> MessagePrivate { + fn decode(_: ClientProt, mut buf: Packet) -> MessagePrivate { return MessagePrivate::new( buf.g8s(), unsafe { buf.data.get_unchecked(buf.pos..buf.pos + buf.data.len() - 8).to_vec() } diff --git a/src/in/message_public.rs b/src/in/message_public.rs index 4157bf2..8e1c719 100644 --- a/src/in/message_public.rs +++ b/src/in/message_public.rs @@ -37,7 +37,7 @@ impl MessageDecoder for MessagePublic { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> MessagePublic { + fn decode(_: ClientProt, mut buf: Packet) -> MessagePublic { return MessagePublic::new( buf.g1(), buf.g1(), diff --git a/src/in/move_click.rs b/src/in/move_click.rs index da7fb36..f81bac7 100644 --- a/src/in/move_click.rs +++ b/src/in/move_click.rs @@ -38,7 +38,7 @@ impl MessageDecoder for MoveClick { } #[inline] - fn decode(prot: ClientProt, buf: &mut Packet) -> MoveClick { + fn decode(prot: ClientProt, mut buf: Packet) -> MoveClick { let ctrl: bool = buf.g1() == 1; let x: u16 = buf.g2(); let z: u16 = buf.g2(); diff --git a/src/in/no_timeout.rs b/src/in/no_timeout.rs index 595c656..57680e3 100644 --- a/src/in/no_timeout.rs +++ b/src/in/no_timeout.rs @@ -22,7 +22,7 @@ impl MessageDecoder for NoTimeout { } #[inline] - fn decode(_: ClientProt, _: &mut Packet) -> NoTimeout { + fn decode(_: ClientProt, _: Packet) -> NoTimeout { return NoTimeout::new(); } } \ No newline at end of file diff --git a/src/in/opheld.rs b/src/in/opheld.rs index d5be104..2a415dd 100644 --- a/src/in/opheld.rs +++ b/src/in/opheld.rs @@ -41,7 +41,7 @@ impl MessageDecoder for OpHeld { } #[inline] - fn decode(prot: ClientProt, buf: &mut Packet) -> OpHeld { + fn decode(prot: ClientProt, mut buf: Packet) -> OpHeld { let op: u8 = match prot { ClientProt::OPHELD1 => 1, ClientProt::OPHELD2 => 2, @@ -99,7 +99,7 @@ impl MessageDecoder for OpHeldT { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> OpHeldT { + fn decode(_: ClientProt, mut buf: Packet) -> OpHeldT { return OpHeldT::new( buf.g2(), buf.g2(), @@ -157,7 +157,7 @@ impl MessageDecoder for OpHeldU { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> OpHeldU { + fn decode(_: ClientProt, mut buf: Packet) -> OpHeldU { return OpHeldU::new( buf.g2(), buf.g2(), diff --git a/src/in/oploc.rs b/src/in/oploc.rs index 49db093..4e67143 100644 --- a/src/in/oploc.rs +++ b/src/in/oploc.rs @@ -41,7 +41,7 @@ impl MessageDecoder for OpLoc { } #[inline] - fn decode(prot: ClientProt, buf: &mut Packet) -> OpLoc { + fn decode(prot: ClientProt, mut buf: Packet) -> OpLoc { let op: u8 = match prot { ClientProt::OPLOC1 => 1, ClientProt::OPLOC2 => 2, @@ -99,7 +99,7 @@ impl MessageDecoder for OpLocT { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> OpLocT { + fn decode(_: ClientProt, mut buf: Packet) -> OpLocT { return OpLocT::new( buf.g2(), buf.g2(), @@ -157,7 +157,7 @@ impl MessageDecoder for OpLocU { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> OpLocU { + fn decode(_: ClientProt, mut buf: Packet) -> OpLocU { return OpLocU::new( buf.g2(), buf.g2(), diff --git a/src/in/opnpc.rs b/src/in/opnpc.rs index fd7b534..bb21032 100644 --- a/src/in/opnpc.rs +++ b/src/in/opnpc.rs @@ -33,7 +33,7 @@ impl MessageDecoder for OpNpc { } #[inline] - fn decode(prot: ClientProt, buf: &mut Packet) -> OpNpc { + fn decode(prot: ClientProt, mut buf: Packet) -> OpNpc { let op: u8 = match prot { ClientProt::OPNPC1 => 1, ClientProt::OPNPC2 => 2, @@ -81,7 +81,7 @@ impl MessageDecoder for OpNpcT { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> OpNpcT { + fn decode(_: ClientProt, mut buf: Packet) -> OpNpcT { return OpNpcT::new( buf.g2(), buf.g2(), @@ -129,7 +129,7 @@ impl MessageDecoder for OpNpcU { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> OpNpcU { + fn decode(_: ClientProt, mut buf: Packet) -> OpNpcU { return OpNpcU::new( buf.g2(), buf.g2(), diff --git a/src/in/opobj.rs b/src/in/opobj.rs index 5b791a9..c4445e8 100644 --- a/src/in/opobj.rs +++ b/src/in/opobj.rs @@ -41,7 +41,7 @@ impl MessageDecoder for OpObj { } #[inline] - fn decode(prot: ClientProt, buf: &mut Packet) -> OpObj { + fn decode(prot: ClientProt, mut buf: Packet) -> OpObj { let op: u8 = match prot { ClientProt::OPOBJ1 => 1, ClientProt::OPOBJ2 => 2, @@ -99,7 +99,7 @@ impl MessageDecoder for OpObjT { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> OpObjT { + fn decode(_: ClientProt, mut buf: Packet) -> OpObjT { return OpObjT::new( buf.g2(), buf.g2(), @@ -157,7 +157,7 @@ impl MessageDecoder for OpObjU { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> OpObjU { + fn decode(_: ClientProt, mut buf: Packet) -> OpObjU { return OpObjU::new( buf.g2(), buf.g2(), diff --git a/src/in/opplayer.rs b/src/in/opplayer.rs index bd55a14..aaa96d3 100644 --- a/src/in/opplayer.rs +++ b/src/in/opplayer.rs @@ -33,7 +33,7 @@ impl MessageDecoder for OpPlayer { } #[inline] - fn decode(prot: ClientProt, buf: &mut Packet) -> OpPlayer { + fn decode(prot: ClientProt, mut buf: Packet) -> OpPlayer { let op: u8 = match prot { ClientProt::OPPLAYER1 => 1, ClientProt::OPPLAYER2 => 2, @@ -80,7 +80,7 @@ impl MessageDecoder for OpPlayerT { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> OpPlayerT { + fn decode(_: ClientProt, mut buf: Packet) -> OpPlayerT { return OpPlayerT::new( buf.g2(), buf.g2(), @@ -128,7 +128,7 @@ impl MessageDecoder for OpPlayerU { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> OpPlayerU { + fn decode(_: ClientProt, mut buf: Packet) -> OpPlayerU { return OpPlayerU::new( buf.g2(), buf.g2(), diff --git a/src/in/rebuild_getmaps.rs b/src/in/rebuild_getmaps.rs index f33499f..2bc498a 100644 --- a/src/in/rebuild_getmaps.rs +++ b/src/in/rebuild_getmaps.rs @@ -27,7 +27,7 @@ impl MessageDecoder for RebuildGetMaps { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> RebuildGetMaps { + fn decode(_: ClientProt, mut buf: Packet) -> RebuildGetMaps { let mut maps: Vec = vec![0; buf.data.len() / 3]; for index in 0..maps.len() { unsafe { *maps.as_mut_ptr().add(index) = buf.g3() as u32 }; diff --git a/src/in/reportabuse.rs b/src/in/reportabuse.rs index a10a90c..b545247 100644 --- a/src/in/reportabuse.rs +++ b/src/in/reportabuse.rs @@ -37,7 +37,7 @@ impl MessageDecoder for ReportAbuse { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> ReportAbuse { + fn decode(_: ClientProt, mut buf: Packet) -> ReportAbuse { return ReportAbuse::new( buf.g8s(), buf.g1(), diff --git a/src/in/resume_countdialog.rs b/src/in/resume_countdialog.rs index eefb562..b293fb1 100644 --- a/src/in/resume_countdialog.rs +++ b/src/in/resume_countdialog.rs @@ -27,7 +27,7 @@ impl MessageDecoder for ResumePCountDialog { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> ResumePCountDialog { + fn decode(_: ClientProt, mut buf: Packet) -> ResumePCountDialog { return ResumePCountDialog::new(buf.g4s()); } } \ No newline at end of file diff --git a/src/in/resume_pausebutton.rs b/src/in/resume_pausebutton.rs index e3dad49..6348810 100644 --- a/src/in/resume_pausebutton.rs +++ b/src/in/resume_pausebutton.rs @@ -27,7 +27,7 @@ impl MessageDecoder for ResumePauseButton { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> ResumePauseButton { + fn decode(_: ClientProt, mut buf: Packet) -> ResumePauseButton { return ResumePauseButton::new(buf.g2()); } } \ No newline at end of file diff --git a/src/in/tutorial_clickside.rs b/src/in/tutorial_clickside.rs index 2ef529e..d471dfe 100644 --- a/src/in/tutorial_clickside.rs +++ b/src/in/tutorial_clickside.rs @@ -27,7 +27,7 @@ impl MessageDecoder for TutorialClickSide { } #[inline] - fn decode(_: ClientProt, buf: &mut Packet) -> TutorialClickSide { + fn decode(_: ClientProt, mut buf: Packet) -> TutorialClickSide { return TutorialClickSide::new(buf.g1()); } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 1ef9a06..066a7c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ use crate::coord::CoordGrid; use crate::grid::ZoneMap; -use crate::message::{IncomingPacket, MessageDecoder, OutgoingPacket}; +use crate::message::{IncomingPacket, MessageDecoder}; use crate::npc::Npc; use crate::out::cam_lookat::CamLookAt; use crate::out::cam_moveto::CamMoveTo; @@ -136,6 +136,7 @@ static mut NPC_RENDERER: Lazy = Lazy::new(NpcRenderer::new); static mut NPC_INFO: Lazy = Lazy::new(NpcInfo::new); static mut ZONE_MAP: Lazy = Lazy::new(ZoneMap::new); +static mut WORD_PACK: Lazy = Lazy::new(WordPack::new); #[wasm_bindgen(js_name = computePlayer)] pub unsafe fn compute_player( @@ -254,27 +255,30 @@ pub unsafe fn compute_player( } #[wasm_bindgen(js_name = playerInfo)] -pub unsafe fn player_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option { +pub unsafe fn player_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option> { if pid == -1 { return None; } - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return Some(OutgoingPacket::new( - Some(PLAYER_INFO.encode( - pos, - &mut **addr_of_mut!(PLAYER_RENDERER), - &**addr_of!(PLAYERS), - &mut **addr_of_mut!(ZONE_MAP), - &**addr_of!(PLAYER_GRID), - player, - dx, - dz, - rebuild, - )), - ServerInternalProt::PLAYER_INFO as i32, - -2, - )); + if let Some(player) = &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + let bytes: Vec = PLAYER_INFO.encode( + pos, + &mut **addr_of_mut!(PLAYER_RENDERER), + &**addr_of!(PLAYERS), + &mut **addr_of_mut!(ZONE_MAP), + &**addr_of!(PLAYER_GRID), + player, + dx, + dz, + rebuild, + ); + let mut buf: Packet = Packet::new(1 + 2 + bytes.len()); + buf.p1(ServerInternalProt::PLAYER_INFO as i32); + buf.pos += 2; + let start = buf.pos; + buf.pdata(&bytes, 0, bytes.len()); + buf.psize2((buf.pos - start) as u16); + return Some(buf.data); } return None; @@ -386,26 +390,29 @@ pub unsafe fn compute_npc( } #[wasm_bindgen(js_name = npcInfo)] -pub unsafe fn npc_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option { +pub unsafe fn npc_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option> { if pid == -1 { return None; } - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return Some(OutgoingPacket::new( - Some(NPC_INFO.encode( - pos, - &mut **addr_of_mut!(NPC_RENDERER), - &mut **addr_of_mut!(NPCS), - &mut **addr_of_mut!(ZONE_MAP), - player, - dx, - dz, - rebuild - )), - ServerInternalProt::NPC_INFO as i32, - -2, - )); + if let Some(player) = &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + let bytes: Vec = NPC_INFO.encode( + pos, + &mut **addr_of_mut!(NPC_RENDERER), + &mut **addr_of_mut!(NPCS), + &mut **addr_of_mut!(ZONE_MAP), + player, + dx, + dz, + rebuild + ); + let mut buf: Packet = Packet::new(1 + 2 + bytes.len()); + buf.p1(ServerInternalProt::NPC_INFO as i32); + buf.pos += 2; + let start = buf.pos; + buf.pdata(&bytes, 0, bytes.len()); + buf.psize2((buf.pos - start) as u16); + return Some(buf.data); } return None; @@ -483,1327 +490,1086 @@ pub unsafe fn cleanup_player_buildarea(pid: i32) { // ---- encoders -#[wasm_bindgen(js_name = camLookAt)] -pub unsafe fn cam_lookat(pid: i32, x: i32, z: i32, height: i32, speed: i32, multiplier: i32) -> Option { +#[wasm_bindgen(js_name = camLookAt)] // buffered +pub unsafe fn cam_lookat(pid: i32, x: i32, z: i32, height: i32, speed: i32, multiplier: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&CamLookAt::new(x, z, height, speed, multiplier)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&CamLookAt::new(x, z, height, speed, multiplier)), + }; } -#[wasm_bindgen(js_name = camMoveTo)] -pub unsafe fn cam_moveto(pid: i32, x: i32, z: i32, height: i32, speed: i32, multiplier: i32) -> Option { +#[wasm_bindgen(js_name = camMoveTo)] // buffered +pub unsafe fn cam_moveto(pid: i32, x: i32, z: i32, height: i32, speed: i32, multiplier: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&CamMoveTo::new(x, z, height, speed, multiplier)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&CamMoveTo::new(x, z, height, speed, multiplier)), + }; } -#[wasm_bindgen(js_name = camReset)] -pub unsafe fn cam_reset(pid: i32) -> Option { +#[wasm_bindgen(js_name = camReset)] // buffered +pub unsafe fn cam_reset(pid: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&CamReset::new()); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&CamReset::new()), + }; } -#[wasm_bindgen(js_name = camShake)] -pub unsafe fn cam_shake(pid: i32, shake: i32, jitter: i32, amplitude: i32, frequency: i32) -> Option { +#[wasm_bindgen(js_name = camShake)] // buffered +pub unsafe fn cam_shake(pid: i32, shake: i32, jitter: i32, amplitude: i32, frequency: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&CamShake::new(shake, jitter, amplitude, frequency)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&CamShake::new(shake, jitter, amplitude, frequency)), + }; } -#[wasm_bindgen(js_name = chatFilterSettings)] -pub unsafe fn chat_filter_settings(pid: i32, public: i32, private: i32, trade: i32) -> Option { +#[wasm_bindgen(js_name = chatFilterSettings)] // buffered +pub unsafe fn chat_filter_settings(pid: i32, public: i32, private: i32, trade: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&ChatFilterSettings::new(public, private, trade)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&ChatFilterSettings::new(public, private, trade)), + }; } -#[wasm_bindgen(js_name = countDialog)] -pub unsafe fn count_dialog(pid: i32) -> Option { +#[wasm_bindgen(js_name = countDialog)] // buffered +pub unsafe fn count_dialog(pid: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&PCountDialog::new()); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&PCountDialog::new()), + }; } -#[wasm_bindgen(js_name = dataLand)] -pub unsafe fn data_land(pid: i32, x: i32, z: i32, offset: i32, length: i32, data: Vec) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&DataLand::new(x, z, offset, length, data)); - } - - return None; +#[wasm_bindgen(js_name = dataLand)] // immediate +pub unsafe fn data_land(x: i32, z: i32, offset: i32, length: i32, data: Vec) -> Option> { + return Player::write(&DataLand::new(x, z, offset, length, data)); } -#[wasm_bindgen(js_name = dataLandDone)] -pub unsafe fn data_land_done(pid: i32, x: i32, z: i32) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&DataLandDone::new(x, z)); - } - - return None; +#[wasm_bindgen(js_name = dataLandDone)] // immediate +pub unsafe fn data_land_done(x: i32, z: i32) -> Option> { + return Player::write(&DataLandDone::new(x, z)); } -#[wasm_bindgen(js_name = dataLoc)] -pub unsafe fn data_loc(pid: i32, x: i32, z: i32, offset: i32, length: i32, data: Vec) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&DataLoc::new(x, z, offset, length, data)); - } - - return None; +#[wasm_bindgen(js_name = dataLoc)] // immediate +pub unsafe fn data_loc(x: i32, z: i32, offset: i32, length: i32, data: Vec) -> Option> { + return Player::write(&DataLoc::new(x, z, offset, length, data)); } -#[wasm_bindgen(js_name = dataLocDone)] -pub unsafe fn data_loc_done(pid: i32, x: i32, z: i32) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&DataLocDone::new(x, z)); - } - - return None; +#[wasm_bindgen(js_name = dataLocDone)] // immediate +pub unsafe fn data_loc_done(x: i32, z: i32) -> Option> { + return Player::write(&DataLocDone::new(x, z)); } -#[wasm_bindgen(js_name = enableTracking)] -pub unsafe fn enable_tracking(pid: i32) -> Option { +#[wasm_bindgen(js_name = enableTracking)] // buffered +pub unsafe fn enable_tracking(pid: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&EnableTracking::new()); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&EnableTracking::new()), + }; } -#[wasm_bindgen(js_name = finishTracking)] -pub unsafe fn finish_tracking(pid: i32) -> Option { +#[wasm_bindgen(js_name = finishTracking)] // buffered +pub unsafe fn finish_tracking(pid: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&FinishTracking::new()); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&FinishTracking::new()), + }; } -#[wasm_bindgen(js_name = hintArrow)] -pub unsafe fn hint_arrow(pid: i32, arrow: i32, nid: i32, pid2: i32, x: i32, z: i32, y: i32) -> Option { +#[wasm_bindgen(js_name = hintArrow)] // buffered +pub unsafe fn hint_arrow(pid: i32, arrow: i32, nid: i32, pid2: i32, x: i32, z: i32, y: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&HintArrow::new(arrow, nid, pid2, x, z, y)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&HintArrow::new(arrow, nid, pid2, x, z, y)), + }; } -#[wasm_bindgen(js_name = ifClose)] -pub unsafe fn if_close(pid: i32) -> Option { +#[wasm_bindgen(js_name = ifClose)] // buffered +pub unsafe fn if_close(pid: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfClose::new()); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfClose::new()), + }; } -#[wasm_bindgen(js_name = ifOpenChat)] -pub unsafe fn if_open_chat(pid: i32, component: i32) -> Option { +#[wasm_bindgen(js_name = ifOpenChat)] // buffered +pub unsafe fn if_open_chat(pid: i32, component: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfOpenChat::new(component)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfOpenChat::new(component)), + }; } -#[wasm_bindgen(js_name = ifOpenMain)] -pub unsafe fn if_open_main(pid: i32, component: i32) -> Option { +#[wasm_bindgen(js_name = ifOpenMain)] // buffered +pub unsafe fn if_open_main(pid: i32, component: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfOpenMain::new(component)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfOpenMain::new(component)), + }; } -#[wasm_bindgen(js_name = ifOpenMainSide)] -pub unsafe fn if_open_main_side(pid: i32, main: i32, side: i32) -> Option { +#[wasm_bindgen(js_name = ifOpenMainSide)] // buffered +pub unsafe fn if_open_main_side(pid: i32, main: i32, side: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfOpenMainSide::new(main, side)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfOpenMainSide::new(main, side)), + }; } -#[wasm_bindgen(js_name = ifOpenSide)] -pub unsafe fn if_open_side(pid: i32, component: i32) -> Option { +#[wasm_bindgen(js_name = ifOpenSide)] // buffered +pub unsafe fn if_open_side(pid: i32, component: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfOpenSide::new(component)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfOpenSide::new(component)), + }; } -#[wasm_bindgen(js_name = ifSetAnim)] -pub unsafe fn if_setanim(pid: i32, component: i32, seq: i32) -> Option { +#[wasm_bindgen(js_name = ifSetAnim)] // buffered +pub unsafe fn if_setanim(pid: i32, component: i32, seq: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetAnim::new(component, seq)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetAnim::new(component, seq)), + }; } -#[wasm_bindgen(js_name = ifSetColour)] -pub unsafe fn if_setcolour(pid: i32, component: i32, colour: i32) -> Option { +#[wasm_bindgen(js_name = ifSetColour)] // buffered +pub unsafe fn if_setcolour(pid: i32, component: i32, colour: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetColour::new(component, colour)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetColour::new(component, colour)), + }; } -#[wasm_bindgen(js_name = ifSetHide)] -pub unsafe fn if_sethide(pid: i32, component: i32, hidden: bool) -> Option { +#[wasm_bindgen(js_name = ifSetHide)] // buffered +pub unsafe fn if_sethide(pid: i32, component: i32, hidden: bool) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetHide::new(component, hidden)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetHide::new(component, hidden)), + }; } -#[wasm_bindgen(js_name = ifSetModel)] -pub unsafe fn if_setmodel(pid: i32, component: i32, model: i32) -> Option { +#[wasm_bindgen(js_name = ifSetModel)] // buffered +pub unsafe fn if_setmodel(pid: i32, component: i32, model: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetModel::new(component, model)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetModel::new(component, model)), + }; } -#[wasm_bindgen(js_name = ifSetNpcHead)] -pub unsafe fn if_setnpchead(pid: i32, component: i32, npc: i32) -> Option { +#[wasm_bindgen(js_name = ifSetNpcHead)] // buffered +pub unsafe fn if_setnpchead(pid: i32, component: i32, npc: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetNpcHead::new(component, npc)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetNpcHead::new(component, npc)), + }; } -#[wasm_bindgen(js_name = ifSetObject)] -pub unsafe fn if_setobject(pid: i32, component: i32, obj: i32, scale: i32) -> Option { +#[wasm_bindgen(js_name = ifSetObject)] // buffered +pub unsafe fn if_setobject(pid: i32, component: i32, obj: i32, scale: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetObject::new(component, obj, scale)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetObject::new(component, obj, scale)), + }; } -#[wasm_bindgen(js_name = ifSetPlayerHead)] -pub unsafe fn if_setplayerhead(pid: i32, component: i32) -> Option { +#[wasm_bindgen(js_name = ifSetPlayerHead)] // buffered +pub unsafe fn if_setplayerhead(pid: i32, component: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetPlayerHead::new(component)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetPlayerHead::new(component)), + }; } -#[wasm_bindgen(js_name = ifSetPosition)] -pub unsafe fn if_setposition(pid: i32, component: i32, x: i32, y: i32) -> Option { +#[wasm_bindgen(js_name = ifSetPosition)] // buffered +pub unsafe fn if_setposition(pid: i32, component: i32, x: i32, y: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetPosition::new(component, x, y)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetPosition::new(component, x, y)), + }; } -#[wasm_bindgen(js_name = ifSetRecol)] -pub unsafe fn if_setrecol(pid: i32, component: i32, src: i32, dst: i32) -> Option { +#[wasm_bindgen(js_name = ifSetRecol)] // buffered +pub unsafe fn if_setrecol(pid: i32, component: i32, src: i32, dst: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetRecol::new(component, src, dst)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetRecol::new(component, src, dst)), + }; } -#[wasm_bindgen(js_name = ifSetTab)] -pub unsafe fn if_settab(pid: i32, component: i32, tab: i32) -> Option { +#[wasm_bindgen(js_name = ifSetTab)] // buffered +pub unsafe fn if_settab(pid: i32, component: i32, tab: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetTab::new(component, tab)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetTab::new(component, tab)), + }; } -#[wasm_bindgen(js_name = ifSetTabActive)] -pub unsafe fn if_settabactive(pid: i32, tab: i32) -> Option { +#[wasm_bindgen(js_name = ifSetTabActive)] // buffered +pub unsafe fn if_settabactive(pid: i32, tab: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetTabActive::new(tab)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetTabActive::new(tab)), + }; } -#[wasm_bindgen(js_name = ifSetText)] -pub unsafe fn if_settext(pid: i32, component: i32, text: String) -> Option { +#[wasm_bindgen(js_name = ifSetText)] // buffered +pub unsafe fn if_settext(pid: i32, component: i32, text: String) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&IfSetText::new(component, text)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&IfSetText::new(component, text)), + }; } -#[wasm_bindgen(js_name = lastLoginInfo)] -pub unsafe fn last_login_info(pid: i32, lastIp: i32, daysSinceLogin: i32, daysSinceRecovery: i32, messages: i32) -> Option { +#[wasm_bindgen(js_name = lastLoginInfo)] // buffered +pub unsafe fn last_login_info(pid: i32, lastIp: i32, daysSinceLogin: i32, daysSinceRecovery: i32, messages: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&LastLoginInfo::new(lastIp, daysSinceLogin, daysSinceRecovery, messages)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&LastLoginInfo::new(lastIp, daysSinceLogin, daysSinceRecovery, messages)), + }; } -#[wasm_bindgen(js_name = locAddChange)] -pub unsafe fn loc_addchange(coord: i32, loc: i32, shape: i32, angle: i32, enclose: bool) -> Option { - return Player::write_zone_message(&LocAddChange::new(coord, loc, shape, angle), enclose); +#[wasm_bindgen(js_name = locAddChange)] // immediate +pub unsafe fn loc_addchange(coord: i32, loc: i32, shape: i32, angle: i32) -> Option> { + return Player::write(&LocAddChange::new(coord, loc, shape, angle)); } -#[wasm_bindgen(js_name = locAnim)] -pub unsafe fn loc_anim(coord: i32, shape: i32, angle: i32, seq: i32, enclose: bool) -> Option { - return Player::write_zone_message(&LocAnim::new(coord, shape, angle, seq), enclose); +#[wasm_bindgen(js_name = locAnim)] // immediate +pub unsafe fn loc_anim(coord: i32, shape: i32, angle: i32, seq: i32) -> Option> { + return Player::write(&LocAnim::new(coord, shape, angle, seq)); } -#[wasm_bindgen(js_name = locDel)] -pub unsafe fn loc_del(coord: i32, shape: i32, angle: i32, enclose: bool) -> Option { - return Player::write_zone_message(&LocDel::new(coord, shape, angle), enclose); +#[wasm_bindgen(js_name = locDel)] // immediate +pub unsafe fn loc_del(coord: i32, shape: i32, angle: i32) -> Option> { + return Player::write(&LocDel::new(coord, shape, angle)); } -#[wasm_bindgen(js_name = locMerge)] -pub unsafe fn loc_merge(srcX: i32, srcZ: i32, shape: i32, angle: i32, loc: i32, start: i32, end: i32, pid: i32, east: i32, south: i32, west: i32, north: i32, enclose: bool) -> Option { - return Player::write_zone_message(&LocMerge::new(srcX, srcZ, shape, angle, loc, start, end, pid, east, south, west, north), enclose); +#[wasm_bindgen(js_name = locMerge)] // immediate +pub unsafe fn loc_merge(srcX: i32, srcZ: i32, shape: i32, angle: i32, loc: i32, start: i32, end: i32, pid: i32, east: i32, south: i32, west: i32, north: i32) -> Option> { + return Player::write(&LocMerge::new(srcX, srcZ, shape, angle, loc, start, end, pid, east, south, west, north)); } -#[wasm_bindgen(js_name = logout)] -pub unsafe fn logout(pid: i32) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&Logout::new()); - } - - return None; +#[wasm_bindgen(js_name = logout)] // immediate +pub unsafe fn logout() -> Option> { + return Player::write(&Logout::new()); } -#[wasm_bindgen(js_name = mapAnim)] -pub unsafe fn map_anim(coord: i32, spotanim: i32, height: i32, delay: i32, enclose: bool) -> Option { - return Player::write_zone_message(&MapAnim::new(coord, spotanim, height, delay), enclose); +#[wasm_bindgen(js_name = mapAnim)] // immediate +pub unsafe fn map_anim(coord: i32, spotanim: i32, height: i32, delay: i32) -> Option> { + return Player::write(&MapAnim::new(coord, spotanim, height, delay)); } -#[wasm_bindgen(js_name = mapProjAnim)] -pub unsafe fn map_projanim(srcX: i32, srcZ: i32, dstX: i32, dstZ: i32, target: i32, spotanim: i32, srcHeight: i32, dstHeight: i32, start: i32, end: i32, peak: i32, arc: i32, enclose: bool) -> Option { - return Player::write_zone_message(&MapProjAnim::new(srcX, srcZ, dstX, dstZ, target, spotanim, srcHeight, dstHeight, start, end, peak, arc), enclose); +#[wasm_bindgen(js_name = mapProjAnim)] // immediate +pub unsafe fn map_projanim(srcX: i32, srcZ: i32, dstX: i32, dstZ: i32, target: i32, spotanim: i32, srcHeight: i32, dstHeight: i32, start: i32, end: i32, peak: i32, arc: i32) -> Option> { + return Player::write(&MapProjAnim::new(srcX, srcZ, dstX, dstZ, target, spotanim, srcHeight, dstHeight, start, end, peak, arc)); } -#[wasm_bindgen(js_name = messageGame)] -pub unsafe fn message_game(pid: i32, msg: String) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&MessageGame::new(msg)); - } - - return None; +#[wasm_bindgen(js_name = messageGame)] // immediate +pub unsafe fn message_game(msg: String) -> Option> { + return Player::write(&MessageGame::new(msg)); } -#[wasm_bindgen(js_name = messagePrivateOut)] -pub unsafe fn message_private_out(pid: i32, from: i64, id: i32, staffModLevel: i32, msg: String) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&MessagePrivateOut::new(from, id, staffModLevel, msg)); - } - - return None; +#[wasm_bindgen(js_name = messagePrivateOut)] // immediate +pub unsafe fn message_private_out(from: i64, id: i32, staffModLevel: i32, msg: String) -> Option> { + return Player::write(&MessagePrivateOut::new(from, id, staffModLevel, msg)); } -#[wasm_bindgen(js_name = midiJingle)] -pub unsafe fn midi_jingle(pid: i32, delay: i32, data: Vec) -> Option { +#[wasm_bindgen(js_name = midiJingle)] // buffered +pub unsafe fn midi_jingle(pid: i32, delay: i32, data: Vec) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&MidiJingle::new(delay, data)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&MidiJingle::new(delay, data)), + }; } -#[wasm_bindgen(js_name = midiSong)] -pub unsafe fn midi_song(pid: i32, name: String, crc: i32, length: i32) -> Option { +#[wasm_bindgen(js_name = midiSong)] // buffered +pub unsafe fn midi_song(pid: i32, name: String, crc: i32, length: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&MidiSong::new(name, crc, length)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&MidiSong::new(name, crc, length)), + }; } -#[wasm_bindgen(js_name = objAdd)] -pub unsafe fn obj_add(coord: i32, obj: i32, count: i32, enclose: bool) -> Option { - return Player::write_zone_message(&ObjAdd::new(coord, obj, count), enclose); +#[wasm_bindgen(js_name = objAdd)] // immediate +pub unsafe fn obj_add(coord: i32, obj: i32, count: i32) -> Option> { + return Player::write(&ObjAdd::new(coord, obj, count)); } -#[wasm_bindgen(js_name = objCount)] -pub unsafe fn obj_count(coord: i32, obj: i32, oldCount: i32, newCount: i32, enclose: bool) -> Option { - return Player::write_zone_message(&ObjCount::new(coord, obj, oldCount, newCount), enclose); +#[wasm_bindgen(js_name = objCount)] // immediate +pub unsafe fn obj_count(coord: i32, obj: i32, oldCount: i32, newCount: i32) -> Option> { + return Player::write(&ObjCount::new(coord, obj, oldCount, newCount)); } -#[wasm_bindgen(js_name = objDel)] -pub unsafe fn obj_del(coord: i32, obj: i32, enclose: bool) -> Option { - return Player::write_zone_message(&ObjDel::new(coord, obj), enclose); +#[wasm_bindgen(js_name = objDel)] // immediate +pub unsafe fn obj_del(coord: i32, obj: i32) -> Option> { + return Player::write(&ObjDel::new(coord, obj)); } -#[wasm_bindgen(js_name = objReveal)] -pub unsafe fn obj_reveal(coord: i32, obj: i32, count: i32, receiver: i32, enclose: bool) -> Option { - return Player::write_zone_message(&ObjReveal::new(coord, obj, count, receiver), enclose); +#[wasm_bindgen(js_name = objReveal)] // immediate +pub unsafe fn obj_reveal(coord: i32, obj: i32, count: i32, receiver: i32) -> Option> { + return Player::write(&ObjReveal::new(coord, obj, count, receiver)); } -#[wasm_bindgen(js_name = rebuildNormal)] -pub unsafe fn rebuild_normal(pid: i32, x: i32, z: i32, squares: Vec, maps: Vec, locs: Vec) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&RebuildNormal::new(x, z, squares, maps, locs)); - } - - return None; +#[wasm_bindgen(js_name = rebuildNormal)] // immediate +pub unsafe fn rebuild_normal(x: i32, z: i32, squares: Vec, maps: Vec, locs: Vec) -> Option> { + return Player::write(&RebuildNormal::new(x, z, squares, maps, locs)); } -#[wasm_bindgen(js_name = resetAnims)] -pub unsafe fn reset_anims(pid: i32) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&ResetAnims::new()); - } - - return None; +#[wasm_bindgen(js_name = resetAnims)] // immediate +pub unsafe fn reset_anims() -> Option> { + return Player::write(&ResetAnims::new()); } -#[wasm_bindgen(js_name = resetClientVarCache)] -pub unsafe fn reset_clientvarcache(pid: i32) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&ResetClientVarCache::new()); - } - - return None; +#[wasm_bindgen(js_name = resetClientVarCache)] // immediate +pub unsafe fn reset_clientvarcache() -> Option> { + return Player::write(&ResetClientVarCache::new()); } -#[wasm_bindgen(js_name = setMultiway)] -pub unsafe fn set_multiway(pid: i32, hidden: bool) -> Option { +#[wasm_bindgen(js_name = setMultiway)] // buffered +pub unsafe fn set_multiway(pid: i32, hidden: bool) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&SetMultiway::new(hidden)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&SetMultiway::new(hidden)), + }; } -#[wasm_bindgen(js_name = synthSound)] -pub unsafe fn synth_sound(pid: i32, synth: i32, loops: i32, delay: i32) -> Option { +#[wasm_bindgen(js_name = synthSound)] // buffered +pub unsafe fn synth_sound(pid: i32, synth: i32, loops: i32, delay: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&SynthSound::new(synth, loops, delay)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&SynthSound::new(synth, loops, delay)), + }; } -#[wasm_bindgen(js_name = tutFlash)] -pub unsafe fn tut_flash(pid: i32, tab: i32) -> Option { +#[wasm_bindgen(js_name = tutFlash)] // buffered +pub unsafe fn tut_flash(pid: i32, tab: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&TutFlash::new(tab)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => return player.buffer(&TutFlash::new(tab)), + }; } -#[wasm_bindgen(js_name = tutOpen)] -pub unsafe fn tut_open(pid: i32, component: i32) -> Option { +#[wasm_bindgen(js_name = tutOpen)] // buffered +pub unsafe fn tut_open(pid: i32, component: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&TutOpen::new(component)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&TutOpen::new(component)), + }; } -#[wasm_bindgen(js_name = unsetMapFlag)] -pub unsafe fn unset_map_flag(pid: i32) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UnsetMapFlag::new()); - } - - return None; +#[wasm_bindgen(js_name = unsetMapFlag)] // immediate +pub unsafe fn unset_map_flag() -> Option> { + return Player::write(&UnsetMapFlag::new()); } -#[wasm_bindgen(js_name = updateFriendList)] -pub unsafe fn update_friendlist(pid: i32, name: i64, node: i32) -> Option { +#[wasm_bindgen(js_name = updateFriendList)] // buffered +pub unsafe fn update_friendlist(pid: i32, name: i64, node: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateFriendList::new(name, node)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&UpdateFriendList::new(name, node)), + }; } -#[wasm_bindgen(js_name = updateIgnoreList)] -pub unsafe fn update_ignorelist(pid: i32, names: Vec) -> Option { +#[wasm_bindgen(js_name = updateIgnoreList)] // buffered +pub unsafe fn update_ignorelist(pid: i32, names: Vec) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateIgnoreList::new(names)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&UpdateIgnoreList::new(names)), + }; } -#[wasm_bindgen(js_name = updateInvFull)] -pub unsafe fn update_inv_full(pid: i32, size: i32, component: i32, objs: Vec) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateInvFull::new(size, component, objs)); - } - - return None; +#[wasm_bindgen(js_name = updateInvFull)] // immediate +pub unsafe fn update_inv_full(size: i32, component: i32, objs: Vec) -> Option> { + return Player::write(&UpdateInvFull::new(size, component, objs)); } -#[wasm_bindgen(js_name = updateInvPartial)] -pub unsafe fn update_inv_partial(pid: i32, component: i32, slots: Vec, objs: Vec) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateInvPartial::new(component, slots, objs)); - } - - return None; +#[wasm_bindgen(js_name = updateInvPartial)] // immediate +pub unsafe fn update_inv_partial(component: i32, slots: Vec, objs: Vec) -> Option> { + return Player::write(&UpdateInvPartial::new(component, slots, objs)); } -#[wasm_bindgen(js_name = updateInvStopTransmit)] -pub unsafe fn update_inv_stop_transmit(pid: i32, component: i32) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateInvStopTransmit::new(component)); - } - - return None; +#[wasm_bindgen(js_name = updateInvStopTransmit)] // immediate +pub unsafe fn update_inv_stop_transmit(component: i32) -> Option> { + return Player::write(&UpdateInvStopTransmit::new(component)); } -#[wasm_bindgen(js_name = updatePid)] -pub unsafe fn update_pid(pid: i32) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdatePid::new(pid)); - } - - return None; +#[wasm_bindgen(js_name = updatePid)] // immediate +pub unsafe fn update_pid(pid: i32) -> Option> { + return Player::write(&UpdatePid::new(pid)); } -#[wasm_bindgen(js_name = updateRebootTimer)] -pub unsafe fn update_reboot_timer(pid: i32, ticks: i32) -> Option { +#[wasm_bindgen(js_name = updateRebootTimer)] // buffered +pub unsafe fn update_reboot_timer(pid: i32, ticks: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateRebootTimer::new(ticks)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&UpdateRebootTimer::new(ticks)), + }; } -#[wasm_bindgen(js_name = updateRunEnergy)] -pub unsafe fn update_runenergy(pid: i32, energy: i32) -> Option { +#[wasm_bindgen(js_name = updateRunEnergy)] // buffered +pub unsafe fn update_runenergy(pid: i32, energy: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateRunEnergy::new(energy)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&UpdateRunEnergy::new(energy)), + }; } -#[wasm_bindgen(js_name = updateRunWeight)] -pub unsafe fn update_runweight(pid: i32, kg: i32) -> Option { +#[wasm_bindgen(js_name = updateRunWeight)] // buffered +pub unsafe fn update_runweight(pid: i32, kg: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateRunWeight::new(kg)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&UpdateRunWeight::new(kg)), + }; } -#[wasm_bindgen(js_name = updateStat)] -pub unsafe fn update_stat(pid: i32, stat: i32, experience: i32, level: i32) -> Option { +#[wasm_bindgen(js_name = updateStat)] // buffered +pub unsafe fn update_stat(pid: i32, stat: i32, experience: i32, level: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateStat::new(stat, experience, level)); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&UpdateStat::new(stat, experience, level)), + }; } -#[wasm_bindgen(js_name = updateZoneFullFollows)] -pub unsafe fn update_zone_full_follows(pid: i32, x: i32, z: i32, originX: i32, originZ: i32) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateZoneFullFollows::new(x, z, originX, originZ)); - } - - return None; +#[wasm_bindgen(js_name = updateZoneFullFollows)] // immediate +pub unsafe fn update_zone_full_follows(x: i32, z: i32, originX: i32, originZ: i32) -> Option> { + return Player::write(&UpdateZoneFullFollows::new(x, z, originX, originZ)); } -#[wasm_bindgen(js_name = updateZonePartialEnclosed)] -pub unsafe fn update_zone_partial_enclosed(pid: i32, x: i32, z: i32, originX: i32, originZ: i32, data: Vec) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateZonePartialEnclosed::new(x, z, originX, originZ, data)); - } - - return None; +#[wasm_bindgen(js_name = updateZonePartialEnclosed)] // immediate +pub unsafe fn update_zone_partial_enclosed(x: i32, z: i32, originX: i32, originZ: i32, data: Vec) -> Option> { + return Player::write(&UpdateZonePartialEnclosed::new(x, z, originX, originZ, data)); } -#[wasm_bindgen(js_name = updateZonePartialFollows)] -pub unsafe fn update_zone_partial_follows(pid: i32, x: i32, z: i32, originX: i32, originZ: i32) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write(&UpdateZonePartialFollows::new(x, z, originX, originZ)); - } - - return None; +#[wasm_bindgen(js_name = updateZonePartialFollows)] // immediate +pub unsafe fn update_zone_partial_follows(x: i32, z: i32, originX: i32, originZ: i32) -> Option> { + return Player::write(&UpdateZonePartialFollows::new(x, z, originX, originZ)); } -#[wasm_bindgen(js_name = varp)] -pub unsafe fn varp(pid: i32, varp: i32, value: i32) -> Option { - if pid == -1 { - return None; - } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return if value >= -128 && value <= 127 { - player.write(&VarpSmall::new(varp, value)) - } else { - player.write(&VarpLarge::new(varp, value)) - } +#[wasm_bindgen(js_name = varp)]// immediate +pub unsafe fn varp(varp: i32, value: i32) -> Option> { + return if value >= -128 && value <= 127 { + Player::write(&VarpSmall::new(varp, value)) + } else { + Player::write(&VarpLarge::new(varp, value)) } - - return None; } #[wasm_bindgen(js_name = nextBufferedWrite)] -pub unsafe fn next_buffered_write(pid: i32) -> Option { +pub unsafe fn next_buffered_write(pid: i32) -> Option> { if pid == -1 { return None; } - - if let Some(Some(ref mut player)) = PLAYERS.get_mut(pid as usize) { - return player.write_queue.pop_front(); - } - - return None; + return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.write_queue.pop_front(), + }; } // ---- decoders -static PACKET_LOOKUP: Lazy>> = Lazy::new(|| { - let mut lookup: HashMap> = HashMap::new(); - lookup.insert(ClientInternalProt::CLIENT_CHEAT as i32, Some(IncomingPacket::new(ClientProt::CLIENT_CHEAT as i32, ClientCheat::length()))); - lookup.insert(ClientInternalProt::CLOSE_MODAL as i32, Some(IncomingPacket::new(ClientProt::CLOSE_MODAL as i32, CloseModal::length()))); - lookup.insert(ClientInternalProt::FRIENDLIST_ADD as i32, Some(IncomingPacket::new(ClientProt::FRIENDLIST_ADD as i32, FriendListAdd::length()))); - lookup.insert(ClientInternalProt::FRIENDLIST_DEL as i32, Some(IncomingPacket::new(ClientProt::FRIENDLIST_DEL as i32, FriendListDel::length()))); - lookup.insert(ClientInternalProt::IDLE_TIMER as i32, Some(IncomingPacket::new(ClientProt::IDLE_TIMER as i32, IdleTimer::length()))); - lookup.insert(ClientInternalProt::IF_BUTTON as i32, Some(IncomingPacket::new(ClientProt::IF_BUTTON as i32, IfButton::length()))); - lookup.insert(ClientInternalProt::IF_PLAYERDESIGN as i32, Some(IncomingPacket::new(ClientProt::IF_PLAYERDESIGN as i32, IfPlayerDesign::length()))); - lookup.insert(ClientInternalProt::IGNORELIST_ADD as i32, Some(IncomingPacket::new(ClientProt::IGNORELIST_ADD as i32, IgnoreListAdd::length()))); - lookup.insert(ClientInternalProt::IGNORELIST_DEL as i32, Some(IncomingPacket::new(ClientProt::IGNORELIST_DEL as i32, IgnoreListDel::length()))); - lookup.insert(ClientInternalProt::INV_BUTTON1 as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTON1 as i32, InvButton::length()))); - lookup.insert(ClientInternalProt::INV_BUTTON2 as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTON2 as i32, InvButton::length()))); - lookup.insert(ClientInternalProt::INV_BUTTON3 as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTON3 as i32, InvButton::length()))); - lookup.insert(ClientInternalProt::INV_BUTTON4 as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTON4 as i32, InvButton::length()))); - lookup.insert(ClientInternalProt::INV_BUTTON5 as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTON5 as i32, InvButton::length()))); - lookup.insert(ClientInternalProt::INV_BUTTOND as i32, Some(IncomingPacket::new(ClientProt::INV_BUTTOND as i32, InvButtonD::length()))); - lookup.insert(ClientInternalProt::MESSAGE_PRIVATE as i32, Some(IncomingPacket::new(ClientProt::MESSAGE_PRIVATE as i32, MessagePrivate::length()))); - lookup.insert(ClientInternalProt::MESSAGE_PUBLIC as i32, Some(IncomingPacket::new(ClientProt::MESSAGE_PUBLIC as i32, MessagePublic::length()))); - lookup.insert(ClientInternalProt::MOVE_MINIMAPCLICK as i32, Some(IncomingPacket::new(ClientProt::MOVE_MINIMAPCLICK as i32, MoveClick::length()))); - lookup.insert(ClientInternalProt::MOVE_GAMECLICK as i32, Some(IncomingPacket::new(ClientProt::MOVE_GAMECLICK as i32, MoveClick::length()))); - lookup.insert(ClientInternalProt::MOVE_OPCLICK as i32, Some(IncomingPacket::new(ClientProt::MOVE_OPCLICK as i32, MoveClick::length()))); - lookup.insert(ClientInternalProt::NO_TIMEOUT as i32, Some(IncomingPacket::new(ClientProt::NO_TIMEOUT as i32, NoTimeout::length()))); - lookup.insert(ClientInternalProt::OPHELD1 as i32, Some(IncomingPacket::new(ClientProt::OPHELD1 as i32, OpHeld::length()))); - lookup.insert(ClientInternalProt::OPHELD2 as i32, Some(IncomingPacket::new(ClientProt::OPHELD2 as i32, OpHeld::length()))); - lookup.insert(ClientInternalProt::OPHELD3 as i32, Some(IncomingPacket::new(ClientProt::OPHELD3 as i32, OpHeld::length()))); - lookup.insert(ClientInternalProt::OPHELD4 as i32, Some(IncomingPacket::new(ClientProt::OPHELD4 as i32, OpHeld::length()))); - lookup.insert(ClientInternalProt::OPHELD5 as i32, Some(IncomingPacket::new(ClientProt::OPHELD5 as i32, OpHeld::length()))); - lookup.insert(ClientInternalProt::OPHELDT as i32, Some(IncomingPacket::new(ClientProt::OPHELDT as i32, OpHeldT::length()))); - lookup.insert(ClientInternalProt::OPHELDU as i32, Some(IncomingPacket::new(ClientProt::OPHELDU as i32, OpHeldU::length()))); - lookup.insert(ClientInternalProt::OPLOC1 as i32, Some(IncomingPacket::new(ClientProt::OPLOC1 as i32, OpLoc::length()))); - lookup.insert(ClientInternalProt::OPLOC2 as i32, Some(IncomingPacket::new(ClientProt::OPLOC2 as i32, OpLoc::length()))); - lookup.insert(ClientInternalProt::OPLOC3 as i32, Some(IncomingPacket::new(ClientProt::OPLOC3 as i32, OpLoc::length()))); - lookup.insert(ClientInternalProt::OPLOC4 as i32, Some(IncomingPacket::new(ClientProt::OPLOC4 as i32, OpLoc::length()))); - lookup.insert(ClientInternalProt::OPLOC5 as i32, Some(IncomingPacket::new(ClientProt::OPLOC5 as i32, OpLoc::length()))); - lookup.insert(ClientInternalProt::OPLOCT as i32, Some(IncomingPacket::new(ClientProt::OPLOCT as i32, OpLocT::length()))); - lookup.insert(ClientInternalProt::OPLOCU as i32, Some(IncomingPacket::new(ClientProt::OPLOCU as i32, OpLocU::length()))); - lookup.insert(ClientInternalProt::OPNPC1 as i32, Some(IncomingPacket::new(ClientProt::OPNPC1 as i32, OpNpc::length()))); - lookup.insert(ClientInternalProt::OPNPC2 as i32, Some(IncomingPacket::new(ClientProt::OPNPC2 as i32, OpNpc::length()))); - lookup.insert(ClientInternalProt::OPNPC3 as i32, Some(IncomingPacket::new(ClientProt::OPNPC3 as i32, OpNpc::length()))); - lookup.insert(ClientInternalProt::OPNPC4 as i32, Some(IncomingPacket::new(ClientProt::OPNPC4 as i32, OpNpc::length()))); - lookup.insert(ClientInternalProt::OPNPC5 as i32, Some(IncomingPacket::new(ClientProt::OPNPC5 as i32, OpNpc::length()))); - lookup.insert(ClientInternalProt::OPNPCT as i32, Some(IncomingPacket::new(ClientProt::OPNPCT as i32, OpNpcT::length()))); - lookup.insert(ClientInternalProt::OPNPCU as i32, Some(IncomingPacket::new(ClientProt::OPNPCU as i32, OpNpcU::length()))); - lookup.insert(ClientInternalProt::OPOBJ1 as i32, Some(IncomingPacket::new(ClientProt::OPOBJ1 as i32, OpObj::length()))); - lookup.insert(ClientInternalProt::OPOBJ2 as i32, Some(IncomingPacket::new(ClientProt::OPOBJ2 as i32, OpObj::length()))); - lookup.insert(ClientInternalProt::OPOBJ3 as i32, Some(IncomingPacket::new(ClientProt::OPOBJ3 as i32, OpObj::length()))); - lookup.insert(ClientInternalProt::OPOBJ4 as i32, Some(IncomingPacket::new(ClientProt::OPOBJ4 as i32, OpObj::length()))); - lookup.insert(ClientInternalProt::OPOBJ5 as i32, Some(IncomingPacket::new(ClientProt::OPOBJ5 as i32, OpObj::length()))); - lookup.insert(ClientInternalProt::OPOBJT as i32, Some(IncomingPacket::new(ClientProt::OPOBJT as i32, OpObjT::length()))); - lookup.insert(ClientInternalProt::OPOBJU as i32, Some(IncomingPacket::new(ClientProt::OPOBJU as i32, OpObjU::length()))); - lookup.insert(ClientInternalProt::OPPLAYER1 as i32, Some(IncomingPacket::new(ClientProt::OPPLAYER1 as i32, OpPlayer::length()))); - lookup.insert(ClientInternalProt::OPPLAYER2 as i32, Some(IncomingPacket::new(ClientProt::OPPLAYER2 as i32, OpPlayer::length()))); - lookup.insert(ClientInternalProt::OPPLAYER3 as i32, Some(IncomingPacket::new(ClientProt::OPPLAYER3 as i32, OpPlayer::length()))); - lookup.insert(ClientInternalProt::OPPLAYER4 as i32, Some(IncomingPacket::new(ClientProt::OPPLAYER4 as i32, OpPlayer::length()))); - lookup.insert(ClientInternalProt::OPPLAYERT as i32, Some(IncomingPacket::new(ClientProt::OPPLAYERT as i32, OpPlayerT::length()))); - lookup.insert(ClientInternalProt::OPPLAYERU as i32, Some(IncomingPacket::new(ClientProt::OPPLAYERU as i32, OpPlayerU::length()))); - lookup.insert(ClientInternalProt::REBUILD_GETMAPS as i32, Some(IncomingPacket::new(ClientProt::REBUILD_GETMAPS as i32, RebuildGetMaps::length()))); - lookup.insert(ClientInternalProt::RESUME_PAUSEBUTTON as i32, Some(IncomingPacket::new(ClientProt::RESUME_PAUSEBUTTON as i32, ResumePauseButton::length()))); - lookup.insert(ClientInternalProt::RESUME_P_COUNTDIALOG as i32, Some(IncomingPacket::new(ClientProt::RESUME_P_COUNTDIALOG as i32, ResumePCountDialog::length()))); - lookup.insert(ClientInternalProt::TUTORIAL_CLICKSIDE as i32, Some(IncomingPacket::new(ClientProt::TUTORIAL_CLICKSIDE as i32, TutorialClickSide::length()))); - lookup.insert(ClientInternalProt::CHAT_SETMODE as i32, Some(IncomingPacket::new(ClientProt::CHAT_SETMODE as i32, ChatSetMode::length()))); - lookup.insert(ClientInternalProt::EVENT_TRACKING as i32, Some(IncomingPacket::new(ClientProt::EVENT_TRACKING as i32, EventTracking::length()))); - lookup.insert(ClientInternalProt::REPORT_ABUSE as i32, Some(IncomingPacket::new(ClientProt::REPORT_ABUSE as i32, ReportAbuse::length()))); - lookup.insert(ClientInternalProt::EVENT_CAMERA_POSITION as i32, Some(IncomingPacket::new(ClientProt::EVENT_CAMERA_POSITION as i32, EventCameraPosition::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC1 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC1 as i32, AnticheatOp1::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC2 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC2 as i32, AnticheatOp2::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC3 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC3 as i32, AnticheatOp3::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC4 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC4 as i32, AnticheatOp4::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC5 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC5 as i32, AnticheatOp5::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC6 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC6 as i32, AnticheatOp6::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC7 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC7 as i32, AnticheatOp7::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC8 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC8 as i32, AnticheatOp8::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_OPLOGIC9 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC9 as i32, AnticheatOp9::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC1 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC1 as i32, AnticheatCycle1::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC2 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC2 as i32, AnticheatCycle2::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC3 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC3 as i32, AnticheatCycle3::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC4 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC4 as i32, AnticheatCycle4::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC5 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC5 as i32, AnticheatCycle5::length()))); - lookup.insert(ClientInternalProt::ANTICHEAT_CYCLELOGIC6 as i32, Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC6 as i32, AnticheatCycle6::length()))); +static PACKET_LOOKUP: Lazy>> = Lazy::new(|| { + let mut lookup: Vec> = vec![None; 255]; + lookup[ClientInternalProt::CLIENT_CHEAT as usize] = Some(IncomingPacket::new(ClientProt::CLIENT_CHEAT as i32, ClientCheat::length())); + lookup[ClientInternalProt::CLOSE_MODAL as usize] = Some(IncomingPacket::new(ClientProt::CLOSE_MODAL as i32, CloseModal::length())); + lookup[ClientInternalProt::FRIENDLIST_ADD as usize] = Some(IncomingPacket::new(ClientProt::FRIENDLIST_ADD as i32, FriendListAdd::length())); + lookup[ClientInternalProt::FRIENDLIST_DEL as usize] = Some(IncomingPacket::new(ClientProt::FRIENDLIST_DEL as i32, FriendListDel::length())); + lookup[ClientInternalProt::IDLE_TIMER as usize] = Some(IncomingPacket::new(ClientProt::IDLE_TIMER as i32, IdleTimer::length())); + lookup[ClientInternalProt::IF_BUTTON as usize] = Some(IncomingPacket::new(ClientProt::IF_BUTTON as i32, IfButton::length())); + lookup[ClientInternalProt::IF_PLAYERDESIGN as usize] = Some(IncomingPacket::new(ClientProt::IF_PLAYERDESIGN as i32, IfPlayerDesign::length())); + lookup[ClientInternalProt::IGNORELIST_ADD as usize] = Some(IncomingPacket::new(ClientProt::IGNORELIST_ADD as i32, IgnoreListAdd::length())); + lookup[ClientInternalProt::IGNORELIST_DEL as usize] = Some(IncomingPacket::new(ClientProt::IGNORELIST_DEL as i32, IgnoreListDel::length())); + lookup[ClientInternalProt::INV_BUTTON1 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON1 as i32, InvButton::length())); + lookup[ClientInternalProt::INV_BUTTON2 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON2 as i32, InvButton::length())); + lookup[ClientInternalProt::INV_BUTTON3 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON3 as i32, InvButton::length())); + lookup[ClientInternalProt::INV_BUTTON4 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON4 as i32, InvButton::length())); + lookup[ClientInternalProt::INV_BUTTON5 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON5 as i32, InvButton::length())); + lookup[ClientInternalProt::INV_BUTTOND as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTOND as i32, InvButtonD::length())); + lookup[ClientInternalProt::MESSAGE_PRIVATE as usize] = Some(IncomingPacket::new(ClientProt::MESSAGE_PRIVATE as i32, MessagePrivate::length())); + lookup[ClientInternalProt::MESSAGE_PUBLIC as usize] = Some(IncomingPacket::new(ClientProt::MESSAGE_PUBLIC as i32, MessagePublic::length())); + lookup[ClientInternalProt::MOVE_MINIMAPCLICK as usize] = Some(IncomingPacket::new(ClientProt::MOVE_MINIMAPCLICK as i32, MoveClick::length())); + lookup[ClientInternalProt::MOVE_GAMECLICK as usize] = Some(IncomingPacket::new(ClientProt::MOVE_GAMECLICK as i32, MoveClick::length())); + lookup[ClientInternalProt::MOVE_OPCLICK as usize] = Some(IncomingPacket::new(ClientProt::MOVE_OPCLICK as i32, MoveClick::length())); + lookup[ClientInternalProt::NO_TIMEOUT as usize] = Some(IncomingPacket::new(ClientProt::NO_TIMEOUT as i32, NoTimeout::length())); + lookup[ClientInternalProt::OPHELD1 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD1 as i32, OpHeld::length())); + lookup[ClientInternalProt::OPHELD2 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD2 as i32, OpHeld::length())); + lookup[ClientInternalProt::OPHELD3 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD3 as i32, OpHeld::length())); + lookup[ClientInternalProt::OPHELD4 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD4 as i32, OpHeld::length())); + lookup[ClientInternalProt::OPHELD5 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD5 as i32, OpHeld::length())); + lookup[ClientInternalProt::OPHELDT as usize] = Some(IncomingPacket::new(ClientProt::OPHELDT as i32, OpHeldT::length())); + lookup[ClientInternalProt::OPHELDU as usize] = Some(IncomingPacket::new(ClientProt::OPHELDU as i32, OpHeldU::length())); + lookup[ClientInternalProt::OPLOC1 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC1 as i32, OpLoc::length())); + lookup[ClientInternalProt::OPLOC2 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC2 as i32, OpLoc::length())); + lookup[ClientInternalProt::OPLOC3 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC3 as i32, OpLoc::length())); + lookup[ClientInternalProt::OPLOC4 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC4 as i32, OpLoc::length())); + lookup[ClientInternalProt::OPLOC5 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC5 as i32, OpLoc::length())); + lookup[ClientInternalProt::OPLOCT as usize] = Some(IncomingPacket::new(ClientProt::OPLOCT as i32, OpLocT::length())); + lookup[ClientInternalProt::OPLOCU as usize] = Some(IncomingPacket::new(ClientProt::OPLOCU as i32, OpLocU::length())); + lookup[ClientInternalProt::OPNPC1 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC1 as i32, OpNpc::length())); + lookup[ClientInternalProt::OPNPC2 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC2 as i32, OpNpc::length())); + lookup[ClientInternalProt::OPNPC3 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC3 as i32, OpNpc::length())); + lookup[ClientInternalProt::OPNPC4 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC4 as i32, OpNpc::length())); + lookup[ClientInternalProt::OPNPC5 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC5 as i32, OpNpc::length())); + lookup[ClientInternalProt::OPNPCT as usize] = Some(IncomingPacket::new(ClientProt::OPNPCT as i32, OpNpcT::length())); + lookup[ClientInternalProt::OPNPCU as usize] = Some(IncomingPacket::new(ClientProt::OPNPCU as i32, OpNpcU::length())); + lookup[ClientInternalProt::OPOBJ1 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ1 as i32, OpObj::length())); + lookup[ClientInternalProt::OPOBJ2 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ2 as i32, OpObj::length())); + lookup[ClientInternalProt::OPOBJ3 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ3 as i32, OpObj::length())); + lookup[ClientInternalProt::OPOBJ4 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ4 as i32, OpObj::length())); + lookup[ClientInternalProt::OPOBJ5 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ5 as i32, OpObj::length())); + lookup[ClientInternalProt::OPOBJT as usize] = Some(IncomingPacket::new(ClientProt::OPOBJT as i32, OpObjT::length())); + lookup[ClientInternalProt::OPOBJU as usize] = Some(IncomingPacket::new(ClientProt::OPOBJU as i32, OpObjU::length())); + lookup[ClientInternalProt::OPPLAYER1 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER1 as i32, OpPlayer::length())); + lookup[ClientInternalProt::OPPLAYER2 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER2 as i32, OpPlayer::length())); + lookup[ClientInternalProt::OPPLAYER3 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER3 as i32, OpPlayer::length())); + lookup[ClientInternalProt::OPPLAYER4 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER4 as i32, OpPlayer::length())); + lookup[ClientInternalProt::OPPLAYERT as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYERT as i32, OpPlayerT::length())); + lookup[ClientInternalProt::OPPLAYERU as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYERU as i32, OpPlayerU::length())); + lookup[ClientInternalProt::REBUILD_GETMAPS as usize] = Some(IncomingPacket::new(ClientProt::REBUILD_GETMAPS as i32, RebuildGetMaps::length())); + lookup[ClientInternalProt::RESUME_PAUSEBUTTON as usize] = Some(IncomingPacket::new(ClientProt::RESUME_PAUSEBUTTON as i32, ResumePauseButton::length())); + lookup[ClientInternalProt::RESUME_P_COUNTDIALOG as usize] = Some(IncomingPacket::new(ClientProt::RESUME_P_COUNTDIALOG as i32, ResumePCountDialog::length())); + lookup[ClientInternalProt::TUTORIAL_CLICKSIDE as usize] = Some(IncomingPacket::new(ClientProt::TUTORIAL_CLICKSIDE as i32, TutorialClickSide::length())); + lookup[ClientInternalProt::CHAT_SETMODE as usize] = Some(IncomingPacket::new(ClientProt::CHAT_SETMODE as i32, ChatSetMode::length())); + lookup[ClientInternalProt::EVENT_TRACKING as usize] = Some(IncomingPacket::new(ClientProt::EVENT_TRACKING as i32, EventTracking::length())); + lookup[ClientInternalProt::REPORT_ABUSE as usize] = Some(IncomingPacket::new(ClientProt::REPORT_ABUSE as i32, ReportAbuse::length())); + lookup[ClientInternalProt::EVENT_CAMERA_POSITION as usize] = Some(IncomingPacket::new(ClientProt::EVENT_CAMERA_POSITION as i32, EventCameraPosition::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC1 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC1 as i32, AnticheatOp1::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC2 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC2 as i32, AnticheatOp2::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC3 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC3 as i32, AnticheatOp3::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC4 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC4 as i32, AnticheatOp4::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC5 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC5 as i32, AnticheatOp5::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC6 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC6 as i32, AnticheatOp6::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC7 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC7 as i32, AnticheatOp7::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC8 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC8 as i32, AnticheatOp8::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC9 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC9 as i32, AnticheatOp9::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC1 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC1 as i32, AnticheatCycle1::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC2 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC2 as i32, AnticheatCycle2::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC3 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC3 as i32, AnticheatCycle3::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC4 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC4 as i32, AnticheatCycle4::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC5 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC5 as i32, AnticheatCycle5::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC6 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC6 as i32, AnticheatCycle6::length())); return lookup; }); #[wasm_bindgen(js_name = nextBufferedRead)] -pub unsafe fn next_buffered_read(id: i32) -> Option { - return match PACKET_LOOKUP.get(&id) { - None => None, - Some(packet) => packet.clone(), +pub unsafe fn next_buffered_read(id: i32) -> i16 { + return match &*PACKET_LOOKUP.as_ptr().add(id as usize) { + None => -1, + Some(packet) => ((packet.id as i16) << 8) | (packet.length as i16 & 0xff), } } -unsafe fn read(bytes: Vec) -> Packet { - let mut buf: Packet = Packet::new(bytes.len()); - buf.pdata(&bytes, 0, bytes.len()); - buf.pos = 0; - return buf; -} - #[wasm_bindgen(js_name = clientCheat)] pub unsafe fn clientCheat(bytes: Vec) -> Option { - return Some(ClientCheat::decode(ClientProt::CLIENT_CHEAT, &mut read(bytes))); + return Some(ClientCheat::decode(ClientProt::CLIENT_CHEAT, Packet::from(bytes))); } #[wasm_bindgen(js_name = closeModal)] pub unsafe fn close_modal(bytes: Vec) -> Option { - return Some(CloseModal::decode(ClientProt::CLOSE_MODAL, &mut read(bytes))); + return Some(CloseModal::decode(ClientProt::CLOSE_MODAL, Packet::from(bytes))); } #[wasm_bindgen(js_name = friendListAdd)] pub unsafe fn friend_list_add(bytes: Vec) -> Option { - return Some(FriendListAdd::decode(ClientProt::FRIENDLIST_ADD, &mut read(bytes))); + return Some(FriendListAdd::decode(ClientProt::FRIENDLIST_ADD, Packet::from(bytes))); } #[wasm_bindgen(js_name = friendListDel)] pub unsafe fn friend_list_del(bytes: Vec) -> Option { - return Some(FriendListDel::decode(ClientProt::FRIENDLIST_DEL, &mut read(bytes))); + return Some(FriendListDel::decode(ClientProt::FRIENDLIST_DEL, Packet::from(bytes))); } #[wasm_bindgen(js_name = idleTimer)] pub unsafe fn idle_timer(bytes: Vec) -> Option { - return Some(IdleTimer::decode(ClientProt::IDLE_TIMER, &mut read(bytes))); + return Some(IdleTimer::decode(ClientProt::IDLE_TIMER, Packet::from(bytes))); } #[wasm_bindgen(js_name = ifButton)] pub unsafe fn if_button(bytes: Vec) -> Option { - return Some(IfButton::decode(ClientProt::IF_BUTTON, &mut read(bytes))); + return Some(IfButton::decode(ClientProt::IF_BUTTON, Packet::from(bytes))); } #[wasm_bindgen(js_name = ifPlayerDesign)] pub unsafe fn if_player_design(bytes: Vec) -> Option { - return Some(IfPlayerDesign::decode(ClientProt::IF_PLAYERDESIGN, &mut read(bytes))); + return Some(IfPlayerDesign::decode(ClientProt::IF_PLAYERDESIGN, Packet::from(bytes))); } #[wasm_bindgen(js_name = ignoreListAdd)] pub unsafe fn ignore_list_add(bytes: Vec) -> Option { - return Some(IgnoreListAdd::decode(ClientProt::IGNORELIST_ADD, &mut read(bytes))); + return Some(IgnoreListAdd::decode(ClientProt::IGNORELIST_ADD, Packet::from(bytes))); } #[wasm_bindgen(js_name = ignoreListDel)] pub unsafe fn ignore_list_del(bytes: Vec) -> Option { - return Some(IgnoreListDel::decode(ClientProt::IGNORELIST_DEL, &mut read(bytes))); + return Some(IgnoreListDel::decode(ClientProt::IGNORELIST_DEL, Packet::from(bytes))); } #[wasm_bindgen(js_name = invButton1)] pub unsafe fn inv_button1(bytes: Vec) -> Option { - return Some(InvButton::decode(ClientProt::INV_BUTTON1, &mut read(bytes))); + return Some(InvButton::decode(ClientProt::INV_BUTTON1, Packet::from(bytes))); } #[wasm_bindgen(js_name = invButton2)] pub unsafe fn inv_button2(bytes: Vec) -> Option { - return Some(InvButton::decode(ClientProt::INV_BUTTON2, &mut read(bytes))); + return Some(InvButton::decode(ClientProt::INV_BUTTON2, Packet::from(bytes))); } #[wasm_bindgen(js_name = invButton3)] pub unsafe fn inv_button3(bytes: Vec) -> Option { - return Some(InvButton::decode(ClientProt::INV_BUTTON3, &mut read(bytes))); + return Some(InvButton::decode(ClientProt::INV_BUTTON3, Packet::from(bytes))); } #[wasm_bindgen(js_name = invButton4)] pub unsafe fn inv_button4(bytes: Vec) -> Option { - return Some(InvButton::decode(ClientProt::INV_BUTTON4, &mut read(bytes))); + return Some(InvButton::decode(ClientProt::INV_BUTTON4, Packet::from(bytes))); } #[wasm_bindgen(js_name = invButton5)] pub unsafe fn inv_button5(bytes: Vec) -> Option { - return Some(InvButton::decode(ClientProt::INV_BUTTON5, &mut read(bytes))); + return Some(InvButton::decode(ClientProt::INV_BUTTON5, Packet::from(bytes))); } #[wasm_bindgen(js_name = invButtonD)] pub unsafe fn inv_buttonD(bytes: Vec) -> Option { - return Some(InvButtonD::decode(ClientProt::INV_BUTTOND, &mut read(bytes))); + return Some(InvButtonD::decode(ClientProt::INV_BUTTOND, Packet::from(bytes))); } #[wasm_bindgen(js_name = messagePrivate)] pub unsafe fn message_private(bytes: Vec) -> Option { - return Some(MessagePrivate::decode(ClientProt::MESSAGE_PRIVATE, &mut read(bytes))); + return Some(MessagePrivate::decode(ClientProt::MESSAGE_PRIVATE, Packet::from(bytes))); } #[wasm_bindgen(js_name = messagePublic)] pub unsafe fn message_public(bytes: Vec) -> Option { - return Some(MessagePublic::decode(ClientProt::MESSAGE_PUBLIC, &mut read(bytes))); + return Some(MessagePublic::decode(ClientProt::MESSAGE_PUBLIC, Packet::from(bytes))); } #[wasm_bindgen(js_name = moveMinimapClick)] pub unsafe fn move_minimap_click(bytes: Vec) -> Option { - return Some(MoveClick::decode(ClientProt::MOVE_MINIMAPCLICK, &mut read(bytes))); + return Some(MoveClick::decode(ClientProt::MOVE_MINIMAPCLICK, Packet::from(bytes))); } #[wasm_bindgen(js_name = moveGameClick)] pub unsafe fn move_game_click(bytes: Vec) -> Option { - return Some(MoveClick::decode(ClientProt::MOVE_GAMECLICK, &mut read(bytes))); + return Some(MoveClick::decode(ClientProt::MOVE_GAMECLICK, Packet::from(bytes))); } #[wasm_bindgen(js_name = moveOpClick)] pub unsafe fn move_op_click(bytes: Vec) -> Option { - return Some(MoveClick::decode(ClientProt::MOVE_OPCLICK, &mut read(bytes))); + return Some(MoveClick::decode(ClientProt::MOVE_OPCLICK, Packet::from(bytes))); } #[wasm_bindgen(js_name = noTimeout)] pub unsafe fn no_timeout(bytes: Vec) -> Option { - return Some(NoTimeout::decode(ClientProt::NO_TIMEOUT, &mut read(bytes))); + return Some(NoTimeout::decode(ClientProt::NO_TIMEOUT, Packet::from(bytes))); } #[wasm_bindgen(js_name = opheld1)] pub unsafe fn opheld1(bytes: Vec) -> Option { - return Some(OpHeld::decode(ClientProt::OPHELD1, &mut read(bytes))); + return Some(OpHeld::decode(ClientProt::OPHELD1, Packet::from(bytes))); } #[wasm_bindgen(js_name = opheld2)] pub unsafe fn opheld2(bytes: Vec) -> Option { - return Some(OpHeld::decode(ClientProt::OPHELD2, &mut read(bytes))); + return Some(OpHeld::decode(ClientProt::OPHELD2, Packet::from(bytes))); } #[wasm_bindgen(js_name = opheld3)] pub unsafe fn opheld3(bytes: Vec) -> Option { - return Some(OpHeld::decode(ClientProt::OPHELD3, &mut read(bytes))); + return Some(OpHeld::decode(ClientProt::OPHELD3, Packet::from(bytes))); } #[wasm_bindgen(js_name = opheld4)] pub unsafe fn opheld4(bytes: Vec) -> Option { - return Some(OpHeld::decode(ClientProt::OPHELD4, &mut read(bytes))); + return Some(OpHeld::decode(ClientProt::OPHELD4, Packet::from(bytes))); } #[wasm_bindgen(js_name = opheld5)] pub unsafe fn opheld5(bytes: Vec) -> Option { - return Some(OpHeld::decode(ClientProt::OPHELD5, &mut read(bytes))); + return Some(OpHeld::decode(ClientProt::OPHELD5, Packet::from(bytes))); } #[wasm_bindgen(js_name = opheldT)] pub unsafe fn opheldT(bytes: Vec) -> Option { - return Some(OpHeldT::decode(ClientProt::OPHELDT, &mut read(bytes))); + return Some(OpHeldT::decode(ClientProt::OPHELDT, Packet::from(bytes))); } #[wasm_bindgen(js_name = opheldU)] pub unsafe fn opheldU(bytes: Vec) -> Option { - return Some(OpHeldU::decode(ClientProt::OPHELDU, &mut read(bytes))); + return Some(OpHeldU::decode(ClientProt::OPHELDU, Packet::from(bytes))); } #[wasm_bindgen(js_name = oploc1)] pub unsafe fn oploc1(bytes: Vec) -> Option { - return Some(OpLoc::decode(ClientProt::OPLOC1, &mut read(bytes))); + return Some(OpLoc::decode(ClientProt::OPLOC1, Packet::from(bytes))); } #[wasm_bindgen(js_name = oploc2)] pub unsafe fn oploc2(bytes: Vec) -> Option { - return Some(OpLoc::decode(ClientProt::OPLOC2, &mut read(bytes))); + return Some(OpLoc::decode(ClientProt::OPLOC2, Packet::from(bytes))); } #[wasm_bindgen(js_name = oploc3)] pub unsafe fn oploc3(bytes: Vec) -> Option { - return Some(OpLoc::decode(ClientProt::OPLOC3, &mut read(bytes))); + return Some(OpLoc::decode(ClientProt::OPLOC3, Packet::from(bytes))); } #[wasm_bindgen(js_name = oploc4)] pub unsafe fn oploc4(bytes: Vec) -> Option { - return Some(OpLoc::decode(ClientProt::OPLOC4, &mut read(bytes))); + return Some(OpLoc::decode(ClientProt::OPLOC4, Packet::from(bytes))); } #[wasm_bindgen(js_name = oploc5)] pub unsafe fn oploc5(bytes: Vec) -> Option { - return Some(OpLoc::decode(ClientProt::OPLOC5, &mut read(bytes))); + return Some(OpLoc::decode(ClientProt::OPLOC5, Packet::from(bytes))); } #[wasm_bindgen(js_name = oplocT)] pub unsafe fn oplocT(bytes: Vec) -> Option { - return Some(OpLocT::decode(ClientProt::OPLOCT, &mut read(bytes))); + return Some(OpLocT::decode(ClientProt::OPLOCT, Packet::from(bytes))); } #[wasm_bindgen(js_name = oplocU)] pub unsafe fn oplocU(bytes: Vec) -> Option { - return Some(OpLocU::decode(ClientProt::OPLOCU, &mut read(bytes))); + return Some(OpLocU::decode(ClientProt::OPLOCU, Packet::from(bytes))); } #[wasm_bindgen(js_name = opnpc1)] pub unsafe fn opnpc1(bytes: Vec) -> Option { - return Some(OpNpc::decode(ClientProt::OPNPC1, &mut read(bytes))); + return Some(OpNpc::decode(ClientProt::OPNPC1, Packet::from(bytes))); } #[wasm_bindgen(js_name = opnpc2)] pub unsafe fn opnpc2(bytes: Vec) -> Option { - return Some(OpNpc::decode(ClientProt::OPNPC2, &mut read(bytes))); + return Some(OpNpc::decode(ClientProt::OPNPC2, Packet::from(bytes))); } #[wasm_bindgen(js_name = opnpc3)] pub unsafe fn opnpc3(bytes: Vec) -> Option { - return Some(OpNpc::decode(ClientProt::OPNPC3, &mut read(bytes))); + return Some(OpNpc::decode(ClientProt::OPNPC3, Packet::from(bytes))); } #[wasm_bindgen(js_name = opnpc4)] pub unsafe fn opnpc4(bytes: Vec) -> Option { - return Some(OpNpc::decode(ClientProt::OPNPC4, &mut read(bytes))); + return Some(OpNpc::decode(ClientProt::OPNPC4, Packet::from(bytes))); } #[wasm_bindgen(js_name = opnpc5)] pub unsafe fn opnpc5(bytes: Vec) -> Option { - return Some(OpNpc::decode(ClientProt::OPNPC5, &mut read(bytes))); + return Some(OpNpc::decode(ClientProt::OPNPC5, Packet::from(bytes))); } #[wasm_bindgen(js_name = opnpcT)] pub unsafe fn opnpcT(bytes: Vec) -> Option { - return Some(OpNpcT::decode(ClientProt::OPNPCT, &mut read(bytes))); + return Some(OpNpcT::decode(ClientProt::OPNPCT, Packet::from(bytes))); } #[wasm_bindgen(js_name = opnpcU)] pub unsafe fn opnpcU(bytes: Vec) -> Option { - return Some(OpNpcU::decode(ClientProt::OPNPCU, &mut read(bytes))); + return Some(OpNpcU::decode(ClientProt::OPNPCU, Packet::from(bytes))); } #[wasm_bindgen(js_name = opobj1)] pub unsafe fn opobj1(bytes: Vec) -> Option { - return Some(OpObj::decode(ClientProt::OPOBJ1, &mut read(bytes))); + return Some(OpObj::decode(ClientProt::OPOBJ1, Packet::from(bytes))); } #[wasm_bindgen(js_name = opobj2)] pub unsafe fn opobj2(bytes: Vec) -> Option { - return Some(OpObj::decode(ClientProt::OPOBJ2, &mut read(bytes))); + return Some(OpObj::decode(ClientProt::OPOBJ2, Packet::from(bytes))); } #[wasm_bindgen(js_name = opobj3)] pub unsafe fn opobj3(bytes: Vec) -> Option { - return Some(OpObj::decode(ClientProt::OPOBJ3, &mut read(bytes))); + return Some(OpObj::decode(ClientProt::OPOBJ3, Packet::from(bytes))); } #[wasm_bindgen(js_name = opobj4)] pub unsafe fn opobj4(bytes: Vec) -> Option { - return Some(OpObj::decode(ClientProt::OPOBJ4, &mut read(bytes))); + return Some(OpObj::decode(ClientProt::OPOBJ4, Packet::from(bytes))); } #[wasm_bindgen(js_name = opobj5)] pub unsafe fn opobj5(bytes: Vec) -> Option { - return Some(OpObj::decode(ClientProt::OPOBJ5, &mut read(bytes))); + return Some(OpObj::decode(ClientProt::OPOBJ5, Packet::from(bytes))); } #[wasm_bindgen(js_name = opobjT)] pub unsafe fn opobjT(bytes: Vec) -> Option { - return Some(OpObjT::decode(ClientProt::OPOBJT, &mut read(bytes))); + return Some(OpObjT::decode(ClientProt::OPOBJT, Packet::from(bytes))); } #[wasm_bindgen(js_name = opobjU)] pub unsafe fn opobjU(bytes: Vec) -> Option { - return Some(OpObjU::decode(ClientProt::OPOBJU, &mut read(bytes))); + return Some(OpObjU::decode(ClientProt::OPOBJU, Packet::from(bytes))); } #[wasm_bindgen(js_name = opplayer1)] pub unsafe fn opplayer1(bytes: Vec) -> Option { - return Some(OpPlayer::decode(ClientProt::OPPLAYER1, &mut read(bytes))); + return Some(OpPlayer::decode(ClientProt::OPPLAYER1, Packet::from(bytes))); } #[wasm_bindgen(js_name = opplayer2)] pub unsafe fn opplayer2(bytes: Vec) -> Option { - return Some(OpPlayer::decode(ClientProt::OPPLAYER2, &mut read(bytes))); + return Some(OpPlayer::decode(ClientProt::OPPLAYER2, Packet::from(bytes))); } #[wasm_bindgen(js_name = opplayer3)] pub unsafe fn opplayer3(bytes: Vec) -> Option { - return Some(OpPlayer::decode(ClientProt::OPPLAYER3, &mut read(bytes))); + return Some(OpPlayer::decode(ClientProt::OPPLAYER3, Packet::from(bytes))); } #[wasm_bindgen(js_name = opplayer4)] pub unsafe fn opplayer4(bytes: Vec) -> Option { - return Some(OpPlayer::decode(ClientProt::OPPLAYER4, &mut read(bytes))); + return Some(OpPlayer::decode(ClientProt::OPPLAYER4, Packet::from(bytes))); } #[wasm_bindgen(js_name = opplayerT)] pub unsafe fn opplayerT(bytes: Vec) -> Option { - return Some(OpPlayerT::decode(ClientProt::OPPLAYERT, &mut read(bytes))); + return Some(OpPlayerT::decode(ClientProt::OPPLAYERT, Packet::from(bytes))); } #[wasm_bindgen(js_name = opplayerU)] pub unsafe fn opplayerU(bytes: Vec) -> Option { - return Some(OpPlayerU::decode(ClientProt::OPPLAYERU, &mut read(bytes))); + return Some(OpPlayerU::decode(ClientProt::OPPLAYERU, Packet::from(bytes))); } #[wasm_bindgen(js_name = rebuildGetMaps)] pub unsafe fn rebuild_getmaps(bytes: Vec) -> Option { - return Some(RebuildGetMaps::decode(ClientProt::REBUILD_GETMAPS, &mut read(bytes))); + return Some(RebuildGetMaps::decode(ClientProt::REBUILD_GETMAPS, Packet::from(bytes))); } #[wasm_bindgen(js_name = resumePauseButton)] pub unsafe fn resume_pausebutton(bytes: Vec) -> Option { - return Some(ResumePauseButton::decode(ClientProt::RESUME_PAUSEBUTTON, &mut read(bytes))); + return Some(ResumePauseButton::decode(ClientProt::RESUME_PAUSEBUTTON, Packet::from(bytes))); } #[wasm_bindgen(js_name = resumeCountDialog)] pub unsafe fn resume_countdialog(bytes: Vec) -> Option { - return Some(ResumePCountDialog::decode(ClientProt::RESUME_P_COUNTDIALOG, &mut read(bytes))); + return Some(ResumePCountDialog::decode(ClientProt::RESUME_P_COUNTDIALOG, Packet::from(bytes))); } #[wasm_bindgen(js_name = tutorialClickSide)] pub unsafe fn tutorial_clickside(bytes: Vec) -> Option { - return Some(TutorialClickSide::decode(ClientProt::TUTORIAL_CLICKSIDE, &mut read(bytes))); + return Some(TutorialClickSide::decode(ClientProt::TUTORIAL_CLICKSIDE, Packet::from(bytes))); } #[wasm_bindgen(js_name = chatSetMode)] pub unsafe fn chat_setmode(bytes: Vec) -> Option { - return Some(ChatSetMode::decode(ClientProt::CHAT_SETMODE, &mut read(bytes))); + return Some(ChatSetMode::decode(ClientProt::CHAT_SETMODE, Packet::from(bytes))); } #[wasm_bindgen(js_name = eventTracking)] pub unsafe fn event_tracking(bytes: Vec) -> Option { - return Some(EventTracking::decode(ClientProt::EVENT_TRACKING, &mut read(bytes))); + return Some(EventTracking::decode(ClientProt::EVENT_TRACKING, Packet::from(bytes))); } #[wasm_bindgen(js_name = reportAbuse)] pub unsafe fn report_abuse(bytes: Vec) -> Option { - return Some(ReportAbuse::decode(ClientProt::REPORT_ABUSE, &mut read(bytes))); + return Some(ReportAbuse::decode(ClientProt::REPORT_ABUSE, Packet::from(bytes))); } #[wasm_bindgen(js_name = eventCameraPosition)] pub unsafe fn event_camera_position(bytes: Vec) -> Option { - return Some(EventCameraPosition::decode(ClientProt::EVENT_CAMERA_POSITION, &mut read(bytes))); + return Some(EventCameraPosition::decode(ClientProt::EVENT_CAMERA_POSITION, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatOp1)] pub unsafe fn anticheatop1(bytes: Vec) -> Option { - return Some(AnticheatOp1::decode(ClientProt::ANTICHEAT_OPLOGIC1, &mut read(bytes))); + return Some(AnticheatOp1::decode(ClientProt::ANTICHEAT_OPLOGIC1, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatOp2)] pub unsafe fn anticheatop2(bytes: Vec) -> Option { - return Some(AnticheatOp2::decode(ClientProt::ANTICHEAT_OPLOGIC2, &mut read(bytes))); + return Some(AnticheatOp2::decode(ClientProt::ANTICHEAT_OPLOGIC2, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatOp3)] pub unsafe fn anticheatop3(bytes: Vec) -> Option { - return Some(AnticheatOp3::decode(ClientProt::ANTICHEAT_OPLOGIC3, &mut read(bytes))); + return Some(AnticheatOp3::decode(ClientProt::ANTICHEAT_OPLOGIC3, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatOp4)] pub unsafe fn anticheatop4(bytes: Vec) -> Option { - return Some(AnticheatOp4::decode(ClientProt::ANTICHEAT_OPLOGIC4, &mut read(bytes))); + return Some(AnticheatOp4::decode(ClientProt::ANTICHEAT_OPLOGIC4, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatOp5)] pub unsafe fn anticheatop5(bytes: Vec) -> Option { - return Some(AnticheatOp5::decode(ClientProt::ANTICHEAT_OPLOGIC5, &mut read(bytes))); + return Some(AnticheatOp5::decode(ClientProt::ANTICHEAT_OPLOGIC5, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatOp6)] pub unsafe fn anticheatop6(bytes: Vec) -> Option { - return Some(AnticheatOp6::decode(ClientProt::ANTICHEAT_OPLOGIC6, &mut read(bytes))); + return Some(AnticheatOp6::decode(ClientProt::ANTICHEAT_OPLOGIC6, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatOp7)] pub unsafe fn anticheatop7(bytes: Vec) -> Option { - return Some(AnticheatOp7::decode(ClientProt::ANTICHEAT_OPLOGIC7, &mut read(bytes))); + return Some(AnticheatOp7::decode(ClientProt::ANTICHEAT_OPLOGIC7, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatOp8)] pub unsafe fn anticheatop8(bytes: Vec) -> Option { - return Some(AnticheatOp8::decode(ClientProt::ANTICHEAT_OPLOGIC8, &mut read(bytes))); + return Some(AnticheatOp8::decode(ClientProt::ANTICHEAT_OPLOGIC8, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatOp9)] pub unsafe fn anticheatop9(bytes: Vec) -> Option { - return Some(AnticheatOp9::decode(ClientProt::ANTICHEAT_OPLOGIC9, &mut read(bytes))); + return Some(AnticheatOp9::decode(ClientProt::ANTICHEAT_OPLOGIC9, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatCycle1)] pub unsafe fn anticheatcycle1(bytes: Vec) -> Option { - return Some(AnticheatCycle1::decode(ClientProt::ANTICHEAT_CYCLELOGIC1, &mut read(bytes))); + return Some(AnticheatCycle1::decode(ClientProt::ANTICHEAT_CYCLELOGIC1, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatCycle2)] pub unsafe fn anticheatcycle2(bytes: Vec) -> Option { - return Some(AnticheatCycle2::decode(ClientProt::ANTICHEAT_CYCLELOGIC2, &mut read(bytes))); + return Some(AnticheatCycle2::decode(ClientProt::ANTICHEAT_CYCLELOGIC2, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatCycle3)] pub unsafe fn anticheatcycle3(bytes: Vec) -> Option { - return Some(AnticheatCycle3::decode(ClientProt::ANTICHEAT_CYCLELOGIC3, &mut read(bytes))); + return Some(AnticheatCycle3::decode(ClientProt::ANTICHEAT_CYCLELOGIC3, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatCycle4)] pub unsafe fn anticheatcycle4(bytes: Vec) -> Option { - return Some(AnticheatCycle4::decode(ClientProt::ANTICHEAT_CYCLELOGIC4, &mut read(bytes))); + return Some(AnticheatCycle4::decode(ClientProt::ANTICHEAT_CYCLELOGIC4, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatCycle5)] pub unsafe fn anticheatcycle5(bytes: Vec) -> Option { - return Some(AnticheatCycle5::decode(ClientProt::ANTICHEAT_CYCLELOGIC5, &mut read(bytes))); + return Some(AnticheatCycle5::decode(ClientProt::ANTICHEAT_CYCLELOGIC5, Packet::from(bytes))); } #[wasm_bindgen(js_name = anticheatCycle6)] pub unsafe fn anticheatcycle6(bytes: Vec) -> Option { - return Some(AnticheatCycle6::decode(ClientProt::ANTICHEAT_CYCLELOGIC6, &mut read(bytes))); + return Some(AnticheatCycle6::decode(ClientProt::ANTICHEAT_CYCLELOGIC6, Packet::from(bytes))); } // ---- misc #[wasm_bindgen(js_name = unpackWords)] pub unsafe fn unpack_words(bytes: Vec, length: usize) -> String { - return WordPack::unpack(&mut Packet::from(bytes), length); + return WORD_PACK.unpack(Packet::from(bytes), length); } #[wasm_bindgen(js_name = packWords)] -pub unsafe fn pack_words(bytes: Vec, msg: String) -> Vec { - let mut buf: Packet = Packet::from(bytes); - WordPack::pack(&mut buf, msg); - return buf.data; +pub unsafe fn pack_words(msg: String) -> Vec { + return WORD_PACK.pack(msg); } diff --git a/src/message.rs b/src/message.rs index 579f6a2..24e9527 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,7 +1,6 @@ use crate::packet::Packet; use crate::priority::ServerProtPriority; use crate::prot::ClientProt; -use wasm_bindgen::prelude::wasm_bindgen; pub trait InfoMessage { fn encode(&self, buf: &mut Packet); @@ -18,41 +17,38 @@ pub trait MessageEncoder { pub trait MessageDecoder { fn length() -> i32; - fn decode(prot: ClientProt, buf: &mut Packet) -> T; -} - -#[wasm_bindgen] -#[derive(Clone)] // for VecDeque -pub struct OutgoingPacket { - #[wasm_bindgen(getter_with_clone, readonly)] - pub bytes: Option>, - #[wasm_bindgen(readonly)] - pub id: i32, - #[wasm_bindgen(readonly)] - pub length: i32, -} - -impl OutgoingPacket { - #[inline] - pub fn new( - bytes: Option>, - id: i32, - length: i32 - ) -> OutgoingPacket { - return OutgoingPacket { - bytes, - id, - length, - } - } -} + fn decode(prot: ClientProt, buf: Packet) -> T; +} + +// #[wasm_bindgen] +// #[derive(Clone)] +// pub struct OutgoingPacket { +// #[wasm_bindgen(getter_with_clone, readonly)] +// pub bytes: Option>, +// #[wasm_bindgen(readonly)] +// pub id: i32, +// #[wasm_bindgen(readonly)] +// pub length: i32, +// } +// +// impl OutgoingPacket { +// #[inline] +// pub fn new( +// bytes: Option>, +// id: i32, +// length: i32 +// ) -> OutgoingPacket { +// return OutgoingPacket { +// bytes, +// id, +// length, +// } +// } +// } -#[wasm_bindgen] #[derive(Clone)] pub struct IncomingPacket { - #[wasm_bindgen(readonly)] pub id: i32, - #[wasm_bindgen(readonly)] pub length: i32, } diff --git a/src/out/message_private.rs b/src/out/message_private.rs index 3ab0a0b..8c49e5c 100644 --- a/src/out/message_private.rs +++ b/src/out/message_private.rs @@ -54,7 +54,8 @@ impl MessageEncoder for MessagePrivateOut { buf.p8(self.from); buf.p4(self.id); buf.p1(staff_mod_level); - unsafe { WordPack::pack(buf, self.msg.clone()); } + let bytes: Vec = unsafe { WordPack::new().pack(self.msg.clone()) }; + buf.pdata(&bytes, 0, bytes.len()) } #[inline] diff --git a/src/pack.rs b/src/pack.rs index b2e02b9..9a66882 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -1,6 +1,8 @@ use crate::packet::Packet; -pub struct WordPack; +pub struct WordPack { + buf: Packet, +} impl WordPack { const CHAR_LOOKUP: [char; 61] = [ @@ -13,7 +15,14 @@ impl WordPack { ]; #[inline] - pub unsafe fn unpack(packet: &mut Packet, length: usize) -> String { + pub fn new() -> WordPack { + return WordPack { + buf: Packet::new(100), + }; + } + + #[inline] + pub unsafe fn unpack(&self, mut packet: Packet, length: usize) -> String { let mut char_buffer: Vec = Vec::with_capacity(80); let mut pos: usize = 0; let mut carry: i32 = -1; @@ -61,7 +70,9 @@ impl WordPack { } #[inline] - pub unsafe fn pack(packet: &mut Packet, mut input: String) { + pub unsafe fn pack(&mut self, mut input: String) -> Vec { + self.buf.pos = 0; + if input.len() > 80 { input.truncate(80); } @@ -85,20 +96,22 @@ impl WordPack { if index < 13 { carry = index; } else { - packet.p1(index); + self.buf.p1(index); } } else if index < 13 { - packet.p1((carry << 4) + index); + self.buf.p1((carry << 4) + index); carry = -1; } else { - packet.p1((carry << 4) + (index >> 4)); + self.buf.p1((carry << 4) + (index >> 4)); carry = index & 0xf; } } if carry != -1 { - packet.p1(carry << 4); + self.buf.p1(carry << 4); } + + return self.buf.data.get_unchecked(0..self.buf.pos).to_vec(); } #[inline] diff --git a/src/player.rs b/src/player.rs index 77c421a..1aec5dd 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,8 +1,7 @@ use crate::build::BuildArea; use crate::coord::CoordGrid; -use crate::message::{MessageEncoder, OutgoingPacket}; +use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::visibility::Visibility; use std::collections::VecDeque; @@ -38,7 +37,7 @@ pub struct Player { pub graphic_height: i32, pub graphic_delay: i32, pub exact_move: Option, - pub write_queue: VecDeque, + pub write_queue: VecDeque>, } #[derive(Clone)] @@ -99,31 +98,34 @@ impl Player { } #[inline] - pub fn write(&mut self, message: &dyn MessageEncoder) -> Option { - let mut buf: Packet = Packet::new(message.test()); - message.encode(&mut buf); - let out: OutgoingPacket = OutgoingPacket::new(Some(buf.data), message.id(), message.length()); - return match message.priority() { - ServerProtPriority::Buffered => { - self.write_queue.push_back(out); - return None; - }, - ServerProtPriority::Immediate => Some(out), - }; + pub fn buffer(&mut self, message: &dyn MessageEncoder) -> Option> { + self.write_queue.push_back(Player::write(message).unwrap()); + return None; } #[inline] - pub fn write_zone_message(message: &dyn MessageEncoder, enclose: bool) -> Option { - return if enclose { - let mut buf: Packet = Packet::new(1 + message.test()); - buf.p1(message.id()); - message.encode(&mut buf); - Some(OutgoingPacket::new(Some(buf.data), message.id(), message.length())) - } else { - let mut buf: Packet = Packet::new(message.test()); - message.encode(&mut buf); - Some(OutgoingPacket::new(Some(buf.data), message.id(), message.length())) - } + pub fn write(message: &dyn MessageEncoder) -> Option> { + let id: i32 = message.id(); + let offset: usize = match message.length() { + -1 => 1 + 1, + -2 => 1 + 2, + _ => 1 + 0, + }; + let mut buf: Packet = Packet::new(offset + message.test()); + buf.p1(id); + match message.length() { + -1 => buf.pos += 1, + -2 => buf.pos += 2, + _ => {} + }; + let start = buf.pos; + message.encode(&mut buf); + match message.length() { + -1 => buf.psize1((buf.pos - start) as u8), + -2 => buf.psize2((buf.pos - start) as u16), + _ => {} + }; + return Some(buf.data); } #[inline] From fb509979c50b7a9f4c932ff7a9dc53608c46602b Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 31 Mar 2025 18:40:33 -0400 Subject: [PATCH 06/14] feat: macros --- src/lib.rs | 1340 +++++++++------------------------------- src/out/npc_info.rs | 3 +- src/out/player_info.rs | 3 +- src/player.rs | 8 +- 4 files changed, 282 insertions(+), 1072 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 066a7c8..6939504 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,6 +126,39 @@ mod r#in; mod out; mod pack; +macro_rules! read { + ($fn_name:ident, $js_name:literal, $struct:ty, $prot:expr) => { + #[wasm_bindgen(js_name = $js_name)] + pub unsafe fn $fn_name(bytes: Vec) -> $struct { + <$struct>::decode($prot, Packet::from(bytes)) + } + }; +} + +macro_rules! buffer { + ($fn_name:ident, $js_name:literal, $struct:ty, ($($arg_name:ident: $arg_ty:ty),*), ($($arg_val:ident),*)) => { + #[wasm_bindgen(js_name = $js_name)] + pub unsafe fn $fn_name(pid: i32, $($arg_name: $arg_ty),*) -> Option> { + if pid == -1 { + return None; + } + match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { + None => None, + Some(player) => player.buffer(&<$struct>::new($($arg_val),*)), + } + } + }; +} + +macro_rules! write { + ($fn_name:ident, $js_name:literal, $struct:ty, ($($arg_name:ident: $arg_ty:ty),*), ($($arg_val:ident),*)) => { + #[wasm_bindgen(js_name = $js_name)] + pub unsafe fn $fn_name($($arg_name: $arg_ty),*) -> Vec { + Player::write(&<$struct>::new($($arg_val),*)) + } + }; +} + static mut PLAYERS: Lazy>> = Lazy::new(|| vec![None; 2048]); static mut PLAYER_GRID: Lazy>> = Lazy::new(|| HashMap::with_capacity(2048)); static mut PLAYER_RENDERER: Lazy = Lazy::new(PlayerRenderer::new); @@ -255,14 +288,13 @@ pub unsafe fn compute_player( } #[wasm_bindgen(js_name = playerInfo)] -pub unsafe fn player_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option> { +pub unsafe fn player_info(pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option> { if pid == -1 { return None; } if let Some(player) = &mut *PLAYERS.as_mut_ptr().add(pid as usize) { let bytes: Vec = PLAYER_INFO.encode( - pos, &mut **addr_of_mut!(PLAYER_RENDERER), &**addr_of!(PLAYERS), &mut **addr_of_mut!(ZONE_MAP), @@ -275,7 +307,7 @@ pub unsafe fn player_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) let mut buf: Packet = Packet::new(1 + 2 + bytes.len()); buf.p1(ServerInternalProt::PLAYER_INFO as i32); buf.pos += 2; - let start = buf.pos; + let start: usize = buf.pos; buf.pdata(&bytes, 0, bytes.len()); buf.psize2((buf.pos - start) as u16); return Some(buf.data); @@ -390,14 +422,13 @@ pub unsafe fn compute_npc( } #[wasm_bindgen(js_name = npcInfo)] -pub unsafe fn npc_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option> { +pub unsafe fn npc_info(pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option> { if pid == -1 { return None; } if let Some(player) = &mut *PLAYERS.as_mut_ptr().add(pid as usize) { let bytes: Vec = NPC_INFO.encode( - pos, &mut **addr_of_mut!(NPC_RENDERER), &mut **addr_of_mut!(NPCS), &mut **addr_of_mut!(ZONE_MAP), @@ -409,7 +440,7 @@ pub unsafe fn npc_info(pos: usize, pid: i32, dx: i32, dz: i32, rebuild: bool) -> let mut buf: Packet = Packet::new(1 + 2 + bytes.len()); buf.p1(ServerInternalProt::NPC_INFO as i32); buf.pos += 2; - let start = buf.pos; + let start: usize = buf.pos; buf.pdata(&bytes, 0, bytes.len()); buf.psize2((buf.pos - start) as u16); return Some(buf.data); @@ -490,1080 +521,261 @@ pub unsafe fn cleanup_player_buildarea(pid: i32) { // ---- encoders -#[wasm_bindgen(js_name = camLookAt)] // buffered -pub unsafe fn cam_lookat(pid: i32, x: i32, z: i32, height: i32, speed: i32, multiplier: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&CamLookAt::new(x, z, height, speed, multiplier)), - }; -} - -#[wasm_bindgen(js_name = camMoveTo)] // buffered -pub unsafe fn cam_moveto(pid: i32, x: i32, z: i32, height: i32, speed: i32, multiplier: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&CamMoveTo::new(x, z, height, speed, multiplier)), - }; -} - -#[wasm_bindgen(js_name = camReset)] // buffered -pub unsafe fn cam_reset(pid: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&CamReset::new()), - }; -} - -#[wasm_bindgen(js_name = camShake)] // buffered -pub unsafe fn cam_shake(pid: i32, shake: i32, jitter: i32, amplitude: i32, frequency: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&CamShake::new(shake, jitter, amplitude, frequency)), - }; -} - -#[wasm_bindgen(js_name = chatFilterSettings)] // buffered -pub unsafe fn chat_filter_settings(pid: i32, public: i32, private: i32, trade: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&ChatFilterSettings::new(public, private, trade)), - }; -} - -#[wasm_bindgen(js_name = countDialog)] // buffered -pub unsafe fn count_dialog(pid: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&PCountDialog::new()), - }; -} - -#[wasm_bindgen(js_name = dataLand)] // immediate -pub unsafe fn data_land(x: i32, z: i32, offset: i32, length: i32, data: Vec) -> Option> { - return Player::write(&DataLand::new(x, z, offset, length, data)); -} - -#[wasm_bindgen(js_name = dataLandDone)] // immediate -pub unsafe fn data_land_done(x: i32, z: i32) -> Option> { - return Player::write(&DataLandDone::new(x, z)); -} - -#[wasm_bindgen(js_name = dataLoc)] // immediate -pub unsafe fn data_loc(x: i32, z: i32, offset: i32, length: i32, data: Vec) -> Option> { - return Player::write(&DataLoc::new(x, z, offset, length, data)); -} - -#[wasm_bindgen(js_name = dataLocDone)] // immediate -pub unsafe fn data_loc_done(x: i32, z: i32) -> Option> { - return Player::write(&DataLocDone::new(x, z)); -} - -#[wasm_bindgen(js_name = enableTracking)] // buffered -pub unsafe fn enable_tracking(pid: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&EnableTracking::new()), - }; -} - -#[wasm_bindgen(js_name = finishTracking)] // buffered -pub unsafe fn finish_tracking(pid: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&FinishTracking::new()), - }; -} - -#[wasm_bindgen(js_name = hintArrow)] // buffered -pub unsafe fn hint_arrow(pid: i32, arrow: i32, nid: i32, pid2: i32, x: i32, z: i32, y: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&HintArrow::new(arrow, nid, pid2, x, z, y)), - }; -} - -#[wasm_bindgen(js_name = ifClose)] // buffered -pub unsafe fn if_close(pid: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfClose::new()), - }; -} - -#[wasm_bindgen(js_name = ifOpenChat)] // buffered -pub unsafe fn if_open_chat(pid: i32, component: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfOpenChat::new(component)), - }; -} - -#[wasm_bindgen(js_name = ifOpenMain)] // buffered -pub unsafe fn if_open_main(pid: i32, component: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfOpenMain::new(component)), - }; -} - -#[wasm_bindgen(js_name = ifOpenMainSide)] // buffered -pub unsafe fn if_open_main_side(pid: i32, main: i32, side: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfOpenMainSide::new(main, side)), - }; -} +buffer!(cam_lookat, "camLookAt", CamLookAt, (x: i32, z: i32, height: i32, speed: i32, multiplier: i32), (x, z, height, speed, multiplier)); +buffer!(cam_moveto, "camMoveTo", CamMoveTo, (x: i32, z: i32, height: i32, speed: i32, multiplier: i32), (x, z, height, speed, multiplier)); +buffer!(cam_reset, "camReset", CamReset, (), ()); +buffer!(cam_shake, "camShake", CamShake, (shake: i32, jitter: i32, amplitude: i32, frequency: i32), (shake, jitter, amplitude, frequency)); +buffer!(chat_filter_settings, "chatFilterSettings", ChatFilterSettings, (public: i32, private: i32, trade: i32), (public, private, trade)); +buffer!(count_dialog, "countDialog", PCountDialog, (), ()); +write!(data_land, "dataLand", DataLand, (x: i32, z: i32, offset: i32, length: i32, data: Vec), (x, z, offset, length, data)); +write!(data_land_done, "dataLandDone", DataLandDone, (x: i32, z: i32), (x, z)); +write!(data_loc, "dataLoc", DataLoc, (x: i32, z: i32, offset: i32, length: i32, data: Vec), (x, z, offset, length, data)); +write!(data_loc_done, "dataLocDone", DataLocDone, (x: i32, z: i32), (x, z)); +buffer!(enable_tracking, "enableTracking", EnableTracking, (), ()); +buffer!(finish_tracking, "finishTracking", FinishTracking, (), ()); +buffer!(hint_arrow, "hintArrow", HintArrow, (arrow: i32, nid: i32, pid2: i32, x: i32, z: i32, y: i32), (arrow, nid, pid2, x, z, y)); +buffer!(if_close, "ifClose", IfClose, (), ()); +buffer!(if_open_chat, "ifOpenChat", IfOpenChat, (component: i32), (component)); +buffer!(if_open_main, "ifOpenMain", IfOpenMain, (component: i32), (component)); +buffer!(if_open_main_side, "ifOpenMainSide", IfOpenMainSide, (main: i32, side: i32), (main, side)); +buffer!(if_open_side, "ifOpenSide", IfOpenSide, (component: i32), (component)); +buffer!(if_setanim, "ifSetAnim", IfSetAnim, (component: i32, seq: i32), (component, seq)); +buffer!(if_setcolour, "ifSetColour", IfSetColour, (component: i32, colour: i32), (component, colour)); +buffer!(if_sethide, "ifSetHide", IfSetHide, (component: i32, hidden: bool), (component, hidden)); +buffer!(if_setmodel, "ifSetModel", IfSetModel, (component: i32, model: i32), (component, model)); +buffer!(if_setnpchead, "ifSetNpcHead", IfSetNpcHead, (component: i32, npc: i32), (component, npc)); +buffer!(if_setobject, "ifSetObject", IfSetObject, (component: i32, obj: i32, scale: i32), (component, obj, scale)); +buffer!(if_setplayerhead, "ifSetPlayerHead", IfSetPlayerHead, (component: i32), (component)); +buffer!(if_setposition, "ifSetPosition", IfSetPosition, (component: i32, x: i32, y: i32), (component, x, y)); +buffer!(if_setrecol, "ifSetRecol", IfSetRecol, (component: i32, src: i32, dst: i32), (component, src, dst)); +buffer!(if_settab, "ifSetTab", IfSetTab, (component: i32, tab: i32), (component, tab)); +buffer!(if_settabactive, "ifSetTabActive", IfSetTabActive, (tab: i32), (tab)); +buffer!(if_settext, "ifSetText", IfSetText, (component: i32, text: String), (component, text)); +buffer!(last_login_info, "lastLoginInfo", LastLoginInfo, (lastIp: i32, daysSinceLogin: i32, daysSinceRecovery: i32, messages: i32), (lastIp, daysSinceLogin, daysSinceRecovery, messages)); +write!(loc_addchange, "locAddChange", LocAddChange, (coord: i32, loc: i32, shape: i32, angle: i32), (coord, loc, shape, angle)); +write!(loc_anim, "locAnim", LocAnim, (coord: i32, shape: i32, angle: i32, seq: i32), (coord, shape, angle, seq)); +write!(loc_del, "locDel", LocDel, (coord: i32, shape: i32, angle: i32), (coord, shape, angle)); +write!(loc_merge, "locMerge", LocMerge, (srcX: i32, srcZ: i32, shape: i32, angle: i32, loc: i32, start: i32, end: i32, pid: i32, east: i32, south: i32, west: i32, north: i32), (srcX, srcZ, shape, angle, loc, start, end, pid, east, south, west, north)); +write!(logout, "logout", Logout, (), ()); +write!(map_anim, "mapAnim", MapAnim, (coord: i32, spotanim: i32, height: i32, delay: i32), (coord, spotanim, height, delay)); +write!(map_projanim, "mapProjAnim", MapProjAnim, (srcX: i32, srcZ: i32, dstX: i32, dstZ: i32, target: i32, spotanim: i32, srcHeight: i32, dstHeight: i32, start: i32, end: i32, peak: i32, arc: i32), (srcX, srcZ, dstX, dstZ, target, spotanim, srcHeight, dstHeight, start, end, peak, arc)); +write!(message_game, "messageGame", MessageGame, (msg: String), (msg)); +write!(message_private_out, "messagePrivateOut", MessagePrivateOut, (from: i64, id: i32, staffModLevel: i32, msg: String), (from, id, staffModLevel, msg)); +buffer!(midi_jingle, "midiJingle", MidiJingle, (delay: i32, data: Vec), (delay, data)); +buffer!(midi_song, "midiSong", MidiSong, (name: String, crc: i32, length: i32), (name, crc, length)); +write!(obj_add, "objAdd", ObjAdd, (coord: i32, obj: i32, count: i32), (coord, obj, count)); +write!(obj_count, "objCount", ObjCount, (coord: i32, obj: i32, oldCount: i32, newCount: i32), (coord, obj, oldCount, newCount)); +write!(obj_del, "objDel", ObjDel, (coord: i32, obj: i32), (coord, obj)); +write!(obj_reveal, "objReveal", ObjReveal, (coord: i32, obj: i32, count: i32, receiver: i32), (coord, obj, count, receiver)); +write!(rebuild_normal, "rebuildNormal", RebuildNormal, (x: i32, z: i32, squares: Vec, maps: Vec, locs: Vec), (x, z, squares, maps, locs)); +write!(reset_anims, "resetAnims", ResetAnims, (), ()); +write!(reset_clientvarcache, "resetClientVarCache", ResetClientVarCache, (), ()); +buffer!(set_multiway, "setMultiway", SetMultiway, (hidden: bool), (hidden)); +buffer!(synth_sound, "synthSound", SynthSound, (synth: i32, loops: i32, delay: i32), (synth, loops, delay)); +buffer!(tut_flash, "tutFlash", TutFlash, (tab: i32), (tab)); +buffer!(tut_open, "tutOpen", TutOpen, (component: i32), (component)); +write!(unset_map_flag, "unsetMapFlag", UnsetMapFlag, (), ()); +buffer!(update_friendlist, "updateFriendList", UpdateFriendList, (name: i64, node: i32), (name, node)); +buffer!(update_ignorelist, "updateIgnoreList", UpdateIgnoreList, (names: Vec), (names)); +write!(update_inv_full, "updateInvFull", UpdateInvFull, (size: i32, component: i32, objs: Vec), (size, component, objs)); +write!(update_inv_partial, "updateInvPartial", UpdateInvPartial, (component: i32, slots: Vec, objs: Vec), (component, slots, objs)); +write!(update_inv_stop_transmit, "updateInvStopTransmit", UpdateInvStopTransmit, (component: i32), (component)); +write!(update_pid, "updatePid", UpdatePid, (pid: i32), (pid)); +buffer!(update_reboot_timer, "updateRebootTimer", UpdateRebootTimer, (ticks: i32), (ticks)); +buffer!(update_runenergy, "updateRunEnergy", UpdateRunEnergy, (energy: i32), (energy)); +buffer!(update_runweight, "updateRunWeight", UpdateRunWeight, (kg: i32), (kg)); +buffer!(update_stat, "updateStat", UpdateStat, (stat: i32, experience: i32, level: i32), (stat, experience, level)); +write!(update_zone_full_follows, "updateZoneFullFollows", UpdateZoneFullFollows, (x: i32, z: i32, originX: i32, originZ: i32), (x, z, originX, originZ)); +write!(update_zone_partial_enclosed, "updateZonePartialEnclosed", UpdateZonePartialEnclosed, (x: i32, z: i32, originX: i32, originZ: i32, data: Vec), (x, z, originX, originZ, data)); +write!(update_zone_partial_follows, "updateZonePartialFollows", UpdateZonePartialFollows, (x: i32, z: i32, originX: i32, originZ: i32), (x, z, originX, originZ)); +write!(varp_small, "varpSmall", VarpSmall, (id: i32, value: i32), (id, value)); +write!(varp_large, "varpLarge", VarpLarge, (id: i32, value: i32), (id, value)); -#[wasm_bindgen(js_name = ifOpenSide)] // buffered -pub unsafe fn if_open_side(pid: i32, component: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfOpenSide::new(component)), - }; -} +// ---- decoders -#[wasm_bindgen(js_name = ifSetAnim)] // buffered -pub unsafe fn if_setanim(pid: i32, component: i32, seq: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfSetAnim::new(component, seq)), - }; -} +read!(client_cheat, "clientCheat", ClientCheat, ClientProt::CLIENT_CHEAT); +read!(close_modal, "closeModal", CloseModal, ClientProt::CLOSE_MODAL); +read!(friend_list_add, "friendListAdd", FriendListAdd, ClientProt::FRIENDLIST_ADD); +read!(friend_list_del, "friendListDel", FriendListDel, ClientProt::FRIENDLIST_DEL); +read!(idle_timer, "idleTimer", IdleTimer, ClientProt::IDLE_TIMER); +read!(if_button, "ifButton", IfButton, ClientProt::IF_BUTTON); +read!(if_player_design, "ifPlayerDesign", IfPlayerDesign, ClientProt::IF_PLAYERDESIGN); +read!(ignore_list_add, "ignoreListAdd", IgnoreListAdd, ClientProt::IGNORELIST_ADD); +read!(ignore_list_del, "ignoreListDel", IgnoreListDel, ClientProt::IGNORELIST_DEL); +read!(inv_button1, "invButton1", InvButton, ClientProt::INV_BUTTON1); +read!(inv_button2, "invButton2", InvButton, ClientProt::INV_BUTTON2); +read!(inv_button3, "invButton3", InvButton, ClientProt::INV_BUTTON3); +read!(inv_button4, "invButton4", InvButton, ClientProt::INV_BUTTON4); +read!(inv_button5, "invButton5", InvButton, ClientProt::INV_BUTTON5); +read!(inv_button_d, "invButtonD", InvButtonD, ClientProt::INV_BUTTOND); +read!(message_private, "messagePrivate", MessagePrivate, ClientProt::MESSAGE_PRIVATE); +read!(message_public, "messagePublic", MessagePublic, ClientProt::MESSAGE_PUBLIC); +read!(move_minimap_click, "moveMinimapClick", MoveClick, ClientProt::MOVE_MINIMAPCLICK); +read!(move_game_click, "moveGameClick", MoveClick, ClientProt::MOVE_GAMECLICK); +read!(move_op_click, "moveOpClick", MoveClick, ClientProt::MOVE_OPCLICK); +read!(no_timeout, "noTimeout", NoTimeout, ClientProt::NO_TIMEOUT); +read!(opheld1, "opheld1", OpHeld, ClientProt::OPHELD1); +read!(opheld2, "opheld2", OpHeld, ClientProt::OPHELD2); +read!(opheld3, "opheld3", OpHeld, ClientProt::OPHELD3); +read!(opheld4, "opheld4", OpHeld, ClientProt::OPHELD4); +read!(opheld5, "opheld5", OpHeld, ClientProt::OPHELD5); +read!(opheld_t, "opheldT", OpHeldT, ClientProt::OPHELDT); +read!(opheld_u, "opheldU", OpHeldU, ClientProt::OPHELDU); +read!(oploc1, "oploc1", OpLoc, ClientProt::OPLOC1); +read!(oploc2, "oploc2", OpLoc, ClientProt::OPLOC2); +read!(oploc3, "oploc3", OpLoc, ClientProt::OPLOC3); +read!(oploc4, "oploc4", OpLoc, ClientProt::OPLOC4); +read!(oploc5, "oploc5", OpLoc, ClientProt::OPLOC5); +read!(oploc_t, "oplocT", OpLocT, ClientProt::OPLOCT); +read!(oploc_u, "oplocU", OpLocU, ClientProt::OPLOCU); +read!(opnpc1, "opnpc1", OpNpc, ClientProt::OPNPC1); +read!(opnpc2, "opnpc2", OpNpc, ClientProt::OPNPC2); +read!(opnpc3, "opnpc3", OpNpc, ClientProt::OPNPC3); +read!(opnpc4, "opnpc4", OpNpc, ClientProt::OPNPC4); +read!(opnpc5, "opnpc5", OpNpc, ClientProt::OPNPC5); +read!(opnpc_t, "opnpcT", OpNpcT, ClientProt::OPNPCT); +read!(opnpc_u, "opnpcU", OpNpcU, ClientProt::OPNPCU); +read!(opobj1, "opobj1", OpObj, ClientProt::OPOBJ1); +read!(opobj2, "opobj2", OpObj, ClientProt::OPOBJ2); +read!(opobj3, "opobj3", OpObj, ClientProt::OPOBJ3); +read!(opobj4, "opobj4", OpObj, ClientProt::OPOBJ4); +read!(opobj5, "opobj5", OpObj, ClientProt::OPOBJ5); +read!(opobj_t, "opobjT", OpObjT, ClientProt::OPOBJT); +read!(opobj_u, "opobjU", OpObjU, ClientProt::OPOBJU); +read!(opplayer1, "opplayer1", OpPlayer, ClientProt::OPPLAYER1); +read!(opplayer2, "opplayer2", OpPlayer, ClientProt::OPPLAYER2); +read!(opplayer3, "opplayer3", OpPlayer, ClientProt::OPPLAYER3); +read!(opplayer4, "opplayer4", OpPlayer, ClientProt::OPPLAYER4); +read!(opplayer_t, "opplayerT", OpPlayerT, ClientProt::OPPLAYERT); +read!(opplayer_u, "opplayerU", OpPlayerU, ClientProt::OPPLAYERU); +read!(rebuild_getmaps, "rebuildGetMaps", RebuildGetMaps, ClientProt::REBUILD_GETMAPS); +read!(resume_pausebutton, "resumePauseButton", ResumePauseButton, ClientProt::RESUME_PAUSEBUTTON); +read!(resume_countdialog, "resumeCountDialog", ResumePCountDialog, ClientProt::RESUME_P_COUNTDIALOG); +read!(tutorial_clickside, "tutorialClickSide", TutorialClickSide, ClientProt::TUTORIAL_CLICKSIDE); +read!(chat_setmode, "chatSetMode", ChatSetMode, ClientProt::CHAT_SETMODE); +read!(event_tracking, "eventTracking", EventTracking, ClientProt::EVENT_TRACKING); +read!(report_abuse, "reportAbuse", ReportAbuse, ClientProt::REPORT_ABUSE); +read!(event_camera_position, "eventCameraPosition", EventCameraPosition, ClientProt::EVENT_CAMERA_POSITION); +read!(anticheatop1, "anticheatOp1", AnticheatOp1, ClientProt::ANTICHEAT_OPLOGIC1); +read!(anticheatop2, "anticheatOp2", AnticheatOp2, ClientProt::ANTICHEAT_OPLOGIC2); +read!(anticheatop3, "anticheatOp3", AnticheatOp3, ClientProt::ANTICHEAT_OPLOGIC3); +read!(anticheatop4, "anticheatOp4", AnticheatOp4, ClientProt::ANTICHEAT_OPLOGIC4); +read!(anticheatop5, "anticheatOp5", AnticheatOp5, ClientProt::ANTICHEAT_OPLOGIC5); +read!(anticheatop6, "anticheatOp6", AnticheatOp6, ClientProt::ANTICHEAT_OPLOGIC6); +read!(anticheatop7, "anticheatOp7", AnticheatOp7, ClientProt::ANTICHEAT_OPLOGIC7); +read!(anticheatop8, "anticheatOp8", AnticheatOp8, ClientProt::ANTICHEAT_OPLOGIC8); +read!(anticheatop9, "anticheatOp9", AnticheatOp9, ClientProt::ANTICHEAT_OPLOGIC9); +read!(anticheatcycle1, "anticheatCycle1", AnticheatCycle1, ClientProt::ANTICHEAT_CYCLELOGIC1); +read!(anticheatcycle2, "anticheatCycle2", AnticheatCycle2, ClientProt::ANTICHEAT_CYCLELOGIC2); +read!(anticheatcycle3, "anticheatCycle3", AnticheatCycle3, ClientProt::ANTICHEAT_CYCLELOGIC3); +read!(anticheatcycle4, "anticheatCycle4", AnticheatCycle4, ClientProt::ANTICHEAT_CYCLELOGIC4); +read!(anticheatcycle5, "anticheatCycle5", AnticheatCycle5, ClientProt::ANTICHEAT_CYCLELOGIC5); +read!(anticheatcycle6, "anticheatCycle6", AnticheatCycle6, ClientProt::ANTICHEAT_CYCLELOGIC6); -#[wasm_bindgen(js_name = ifSetColour)] // buffered -pub unsafe fn if_setcolour(pid: i32, component: i32, colour: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfSetColour::new(component, colour)), - }; -} +// ---- misc -#[wasm_bindgen(js_name = ifSetHide)] // buffered -pub unsafe fn if_sethide(pid: i32, component: i32, hidden: bool) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfSetHide::new(component, hidden)), - }; -} +static PACKET_LOOKUP: Lazy>> = Lazy::new(|| { + let mut lookup: Vec> = vec![None; 255]; + lookup[ClientInternalProt::CLIENT_CHEAT as usize] = Some(IncomingPacket::new(ClientProt::CLIENT_CHEAT as i32, ClientCheat::length())); + lookup[ClientInternalProt::CLOSE_MODAL as usize] = Some(IncomingPacket::new(ClientProt::CLOSE_MODAL as i32, CloseModal::length())); + lookup[ClientInternalProt::FRIENDLIST_ADD as usize] = Some(IncomingPacket::new(ClientProt::FRIENDLIST_ADD as i32, FriendListAdd::length())); + lookup[ClientInternalProt::FRIENDLIST_DEL as usize] = Some(IncomingPacket::new(ClientProt::FRIENDLIST_DEL as i32, FriendListDel::length())); + lookup[ClientInternalProt::IDLE_TIMER as usize] = Some(IncomingPacket::new(ClientProt::IDLE_TIMER as i32, IdleTimer::length())); + lookup[ClientInternalProt::IF_BUTTON as usize] = Some(IncomingPacket::new(ClientProt::IF_BUTTON as i32, IfButton::length())); + lookup[ClientInternalProt::IF_PLAYERDESIGN as usize] = Some(IncomingPacket::new(ClientProt::IF_PLAYERDESIGN as i32, IfPlayerDesign::length())); + lookup[ClientInternalProt::IGNORELIST_ADD as usize] = Some(IncomingPacket::new(ClientProt::IGNORELIST_ADD as i32, IgnoreListAdd::length())); + lookup[ClientInternalProt::IGNORELIST_DEL as usize] = Some(IncomingPacket::new(ClientProt::IGNORELIST_DEL as i32, IgnoreListDel::length())); + lookup[ClientInternalProt::INV_BUTTON1 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON1 as i32, InvButton::length())); + lookup[ClientInternalProt::INV_BUTTON2 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON2 as i32, InvButton::length())); + lookup[ClientInternalProt::INV_BUTTON3 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON3 as i32, InvButton::length())); + lookup[ClientInternalProt::INV_BUTTON4 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON4 as i32, InvButton::length())); + lookup[ClientInternalProt::INV_BUTTON5 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON5 as i32, InvButton::length())); + lookup[ClientInternalProt::INV_BUTTOND as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTOND as i32, InvButtonD::length())); + lookup[ClientInternalProt::MESSAGE_PRIVATE as usize] = Some(IncomingPacket::new(ClientProt::MESSAGE_PRIVATE as i32, MessagePrivate::length())); + lookup[ClientInternalProt::MESSAGE_PUBLIC as usize] = Some(IncomingPacket::new(ClientProt::MESSAGE_PUBLIC as i32, MessagePublic::length())); + lookup[ClientInternalProt::MOVE_MINIMAPCLICK as usize] = Some(IncomingPacket::new(ClientProt::MOVE_MINIMAPCLICK as i32, MoveClick::length())); + lookup[ClientInternalProt::MOVE_GAMECLICK as usize] = Some(IncomingPacket::new(ClientProt::MOVE_GAMECLICK as i32, MoveClick::length())); + lookup[ClientInternalProt::MOVE_OPCLICK as usize] = Some(IncomingPacket::new(ClientProt::MOVE_OPCLICK as i32, MoveClick::length())); + lookup[ClientInternalProt::NO_TIMEOUT as usize] = Some(IncomingPacket::new(ClientProt::NO_TIMEOUT as i32, NoTimeout::length())); + lookup[ClientInternalProt::OPHELD1 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD1 as i32, OpHeld::length())); + lookup[ClientInternalProt::OPHELD2 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD2 as i32, OpHeld::length())); + lookup[ClientInternalProt::OPHELD3 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD3 as i32, OpHeld::length())); + lookup[ClientInternalProt::OPHELD4 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD4 as i32, OpHeld::length())); + lookup[ClientInternalProt::OPHELD5 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD5 as i32, OpHeld::length())); + lookup[ClientInternalProt::OPHELDT as usize] = Some(IncomingPacket::new(ClientProt::OPHELDT as i32, OpHeldT::length())); + lookup[ClientInternalProt::OPHELDU as usize] = Some(IncomingPacket::new(ClientProt::OPHELDU as i32, OpHeldU::length())); + lookup[ClientInternalProt::OPLOC1 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC1 as i32, OpLoc::length())); + lookup[ClientInternalProt::OPLOC2 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC2 as i32, OpLoc::length())); + lookup[ClientInternalProt::OPLOC3 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC3 as i32, OpLoc::length())); + lookup[ClientInternalProt::OPLOC4 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC4 as i32, OpLoc::length())); + lookup[ClientInternalProt::OPLOC5 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC5 as i32, OpLoc::length())); + lookup[ClientInternalProt::OPLOCT as usize] = Some(IncomingPacket::new(ClientProt::OPLOCT as i32, OpLocT::length())); + lookup[ClientInternalProt::OPLOCU as usize] = Some(IncomingPacket::new(ClientProt::OPLOCU as i32, OpLocU::length())); + lookup[ClientInternalProt::OPNPC1 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC1 as i32, OpNpc::length())); + lookup[ClientInternalProt::OPNPC2 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC2 as i32, OpNpc::length())); + lookup[ClientInternalProt::OPNPC3 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC3 as i32, OpNpc::length())); + lookup[ClientInternalProt::OPNPC4 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC4 as i32, OpNpc::length())); + lookup[ClientInternalProt::OPNPC5 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC5 as i32, OpNpc::length())); + lookup[ClientInternalProt::OPNPCT as usize] = Some(IncomingPacket::new(ClientProt::OPNPCT as i32, OpNpcT::length())); + lookup[ClientInternalProt::OPNPCU as usize] = Some(IncomingPacket::new(ClientProt::OPNPCU as i32, OpNpcU::length())); + lookup[ClientInternalProt::OPOBJ1 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ1 as i32, OpObj::length())); + lookup[ClientInternalProt::OPOBJ2 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ2 as i32, OpObj::length())); + lookup[ClientInternalProt::OPOBJ3 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ3 as i32, OpObj::length())); + lookup[ClientInternalProt::OPOBJ4 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ4 as i32, OpObj::length())); + lookup[ClientInternalProt::OPOBJ5 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ5 as i32, OpObj::length())); + lookup[ClientInternalProt::OPOBJT as usize] = Some(IncomingPacket::new(ClientProt::OPOBJT as i32, OpObjT::length())); + lookup[ClientInternalProt::OPOBJU as usize] = Some(IncomingPacket::new(ClientProt::OPOBJU as i32, OpObjU::length())); + lookup[ClientInternalProt::OPPLAYER1 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER1 as i32, OpPlayer::length())); + lookup[ClientInternalProt::OPPLAYER2 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER2 as i32, OpPlayer::length())); + lookup[ClientInternalProt::OPPLAYER3 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER3 as i32, OpPlayer::length())); + lookup[ClientInternalProt::OPPLAYER4 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER4 as i32, OpPlayer::length())); + lookup[ClientInternalProt::OPPLAYERT as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYERT as i32, OpPlayerT::length())); + lookup[ClientInternalProt::OPPLAYERU as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYERU as i32, OpPlayerU::length())); + lookup[ClientInternalProt::REBUILD_GETMAPS as usize] = Some(IncomingPacket::new(ClientProt::REBUILD_GETMAPS as i32, RebuildGetMaps::length())); + lookup[ClientInternalProt::RESUME_PAUSEBUTTON as usize] = Some(IncomingPacket::new(ClientProt::RESUME_PAUSEBUTTON as i32, ResumePauseButton::length())); + lookup[ClientInternalProt::RESUME_P_COUNTDIALOG as usize] = Some(IncomingPacket::new(ClientProt::RESUME_P_COUNTDIALOG as i32, ResumePCountDialog::length())); + lookup[ClientInternalProt::TUTORIAL_CLICKSIDE as usize] = Some(IncomingPacket::new(ClientProt::TUTORIAL_CLICKSIDE as i32, TutorialClickSide::length())); + lookup[ClientInternalProt::CHAT_SETMODE as usize] = Some(IncomingPacket::new(ClientProt::CHAT_SETMODE as i32, ChatSetMode::length())); + lookup[ClientInternalProt::EVENT_TRACKING as usize] = Some(IncomingPacket::new(ClientProt::EVENT_TRACKING as i32, EventTracking::length())); + lookup[ClientInternalProt::REPORT_ABUSE as usize] = Some(IncomingPacket::new(ClientProt::REPORT_ABUSE as i32, ReportAbuse::length())); + lookup[ClientInternalProt::EVENT_CAMERA_POSITION as usize] = Some(IncomingPacket::new(ClientProt::EVENT_CAMERA_POSITION as i32, EventCameraPosition::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC1 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC1 as i32, AnticheatOp1::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC2 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC2 as i32, AnticheatOp2::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC3 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC3 as i32, AnticheatOp3::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC4 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC4 as i32, AnticheatOp4::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC5 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC5 as i32, AnticheatOp5::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC6 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC6 as i32, AnticheatOp6::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC7 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC7 as i32, AnticheatOp7::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC8 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC8 as i32, AnticheatOp8::length())); + lookup[ClientInternalProt::ANTICHEAT_OPLOGIC9 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC9 as i32, AnticheatOp9::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC1 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC1 as i32, AnticheatCycle1::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC2 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC2 as i32, AnticheatCycle2::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC3 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC3 as i32, AnticheatCycle3::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC4 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC4 as i32, AnticheatCycle4::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC5 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC5 as i32, AnticheatCycle5::length())); + lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC6 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC6 as i32, AnticheatCycle6::length())); + return lookup; +}); -#[wasm_bindgen(js_name = ifSetModel)] // buffered -pub unsafe fn if_setmodel(pid: i32, component: i32, model: i32) -> Option> { +#[wasm_bindgen(js_name = nextBufferedWrite)] +pub unsafe fn next_buffered_write(pid: i32) -> Option> { if pid == -1 { return None; } return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { None => None, - Some(player) => player.buffer(&IfSetModel::new(component, model)), + Some(player) => player.write_queue.pop_front(), }; } -#[wasm_bindgen(js_name = ifSetNpcHead)] // buffered -pub unsafe fn if_setnpchead(pid: i32, component: i32, npc: i32) -> Option> { - if pid == -1 { - return None; +#[wasm_bindgen(js_name = nextBufferedRead)] +pub unsafe fn next_buffered_read(id: i32) -> i16 { + return match &*PACKET_LOOKUP.as_ptr().add(id as usize) { + None => -1, + Some(packet) => ((packet.id as i16) << 8) | (packet.length as i16 & 0xff), } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfSetNpcHead::new(component, npc)), - }; } -#[wasm_bindgen(js_name = ifSetObject)] // buffered -pub unsafe fn if_setobject(pid: i32, component: i32, obj: i32, scale: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfSetObject::new(component, obj, scale)), - }; -} - -#[wasm_bindgen(js_name = ifSetPlayerHead)] // buffered -pub unsafe fn if_setplayerhead(pid: i32, component: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfSetPlayerHead::new(component)), - }; -} - -#[wasm_bindgen(js_name = ifSetPosition)] // buffered -pub unsafe fn if_setposition(pid: i32, component: i32, x: i32, y: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfSetPosition::new(component, x, y)), - }; -} - -#[wasm_bindgen(js_name = ifSetRecol)] // buffered -pub unsafe fn if_setrecol(pid: i32, component: i32, src: i32, dst: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfSetRecol::new(component, src, dst)), - }; -} - -#[wasm_bindgen(js_name = ifSetTab)] // buffered -pub unsafe fn if_settab(pid: i32, component: i32, tab: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfSetTab::new(component, tab)), - }; -} - -#[wasm_bindgen(js_name = ifSetTabActive)] // buffered -pub unsafe fn if_settabactive(pid: i32, tab: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfSetTabActive::new(tab)), - }; -} - -#[wasm_bindgen(js_name = ifSetText)] // buffered -pub unsafe fn if_settext(pid: i32, component: i32, text: String) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&IfSetText::new(component, text)), - }; -} - -#[wasm_bindgen(js_name = lastLoginInfo)] // buffered -pub unsafe fn last_login_info(pid: i32, lastIp: i32, daysSinceLogin: i32, daysSinceRecovery: i32, messages: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&LastLoginInfo::new(lastIp, daysSinceLogin, daysSinceRecovery, messages)), - }; -} - -#[wasm_bindgen(js_name = locAddChange)] // immediate -pub unsafe fn loc_addchange(coord: i32, loc: i32, shape: i32, angle: i32) -> Option> { - return Player::write(&LocAddChange::new(coord, loc, shape, angle)); -} - -#[wasm_bindgen(js_name = locAnim)] // immediate -pub unsafe fn loc_anim(coord: i32, shape: i32, angle: i32, seq: i32) -> Option> { - return Player::write(&LocAnim::new(coord, shape, angle, seq)); -} - -#[wasm_bindgen(js_name = locDel)] // immediate -pub unsafe fn loc_del(coord: i32, shape: i32, angle: i32) -> Option> { - return Player::write(&LocDel::new(coord, shape, angle)); -} - -#[wasm_bindgen(js_name = locMerge)] // immediate -pub unsafe fn loc_merge(srcX: i32, srcZ: i32, shape: i32, angle: i32, loc: i32, start: i32, end: i32, pid: i32, east: i32, south: i32, west: i32, north: i32) -> Option> { - return Player::write(&LocMerge::new(srcX, srcZ, shape, angle, loc, start, end, pid, east, south, west, north)); -} - -#[wasm_bindgen(js_name = logout)] // immediate -pub unsafe fn logout() -> Option> { - return Player::write(&Logout::new()); -} - -#[wasm_bindgen(js_name = mapAnim)] // immediate -pub unsafe fn map_anim(coord: i32, spotanim: i32, height: i32, delay: i32) -> Option> { - return Player::write(&MapAnim::new(coord, spotanim, height, delay)); -} - -#[wasm_bindgen(js_name = mapProjAnim)] // immediate -pub unsafe fn map_projanim(srcX: i32, srcZ: i32, dstX: i32, dstZ: i32, target: i32, spotanim: i32, srcHeight: i32, dstHeight: i32, start: i32, end: i32, peak: i32, arc: i32) -> Option> { - return Player::write(&MapProjAnim::new(srcX, srcZ, dstX, dstZ, target, spotanim, srcHeight, dstHeight, start, end, peak, arc)); -} - -#[wasm_bindgen(js_name = messageGame)] // immediate -pub unsafe fn message_game(msg: String) -> Option> { - return Player::write(&MessageGame::new(msg)); -} - -#[wasm_bindgen(js_name = messagePrivateOut)] // immediate -pub unsafe fn message_private_out(from: i64, id: i32, staffModLevel: i32, msg: String) -> Option> { - return Player::write(&MessagePrivateOut::new(from, id, staffModLevel, msg)); -} - -#[wasm_bindgen(js_name = midiJingle)] // buffered -pub unsafe fn midi_jingle(pid: i32, delay: i32, data: Vec) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&MidiJingle::new(delay, data)), - }; -} - -#[wasm_bindgen(js_name = midiSong)] // buffered -pub unsafe fn midi_song(pid: i32, name: String, crc: i32, length: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&MidiSong::new(name, crc, length)), - }; -} - -#[wasm_bindgen(js_name = objAdd)] // immediate -pub unsafe fn obj_add(coord: i32, obj: i32, count: i32) -> Option> { - return Player::write(&ObjAdd::new(coord, obj, count)); -} - -#[wasm_bindgen(js_name = objCount)] // immediate -pub unsafe fn obj_count(coord: i32, obj: i32, oldCount: i32, newCount: i32) -> Option> { - return Player::write(&ObjCount::new(coord, obj, oldCount, newCount)); -} - -#[wasm_bindgen(js_name = objDel)] // immediate -pub unsafe fn obj_del(coord: i32, obj: i32) -> Option> { - return Player::write(&ObjDel::new(coord, obj)); -} - -#[wasm_bindgen(js_name = objReveal)] // immediate -pub unsafe fn obj_reveal(coord: i32, obj: i32, count: i32, receiver: i32) -> Option> { - return Player::write(&ObjReveal::new(coord, obj, count, receiver)); -} - -#[wasm_bindgen(js_name = rebuildNormal)] // immediate -pub unsafe fn rebuild_normal(x: i32, z: i32, squares: Vec, maps: Vec, locs: Vec) -> Option> { - return Player::write(&RebuildNormal::new(x, z, squares, maps, locs)); -} - -#[wasm_bindgen(js_name = resetAnims)] // immediate -pub unsafe fn reset_anims() -> Option> { - return Player::write(&ResetAnims::new()); -} - -#[wasm_bindgen(js_name = resetClientVarCache)] // immediate -pub unsafe fn reset_clientvarcache() -> Option> { - return Player::write(&ResetClientVarCache::new()); -} - -#[wasm_bindgen(js_name = setMultiway)] // buffered -pub unsafe fn set_multiway(pid: i32, hidden: bool) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&SetMultiway::new(hidden)), - }; -} - -#[wasm_bindgen(js_name = synthSound)] // buffered -pub unsafe fn synth_sound(pid: i32, synth: i32, loops: i32, delay: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&SynthSound::new(synth, loops, delay)), - }; -} - -#[wasm_bindgen(js_name = tutFlash)] // buffered -pub unsafe fn tut_flash(pid: i32, tab: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => return player.buffer(&TutFlash::new(tab)), - }; -} - -#[wasm_bindgen(js_name = tutOpen)] // buffered -pub unsafe fn tut_open(pid: i32, component: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&TutOpen::new(component)), - }; -} - -#[wasm_bindgen(js_name = unsetMapFlag)] // immediate -pub unsafe fn unset_map_flag() -> Option> { - return Player::write(&UnsetMapFlag::new()); -} - -#[wasm_bindgen(js_name = updateFriendList)] // buffered -pub unsafe fn update_friendlist(pid: i32, name: i64, node: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&UpdateFriendList::new(name, node)), - }; -} - -#[wasm_bindgen(js_name = updateIgnoreList)] // buffered -pub unsafe fn update_ignorelist(pid: i32, names: Vec) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&UpdateIgnoreList::new(names)), - }; -} - -#[wasm_bindgen(js_name = updateInvFull)] // immediate -pub unsafe fn update_inv_full(size: i32, component: i32, objs: Vec) -> Option> { - return Player::write(&UpdateInvFull::new(size, component, objs)); -} - -#[wasm_bindgen(js_name = updateInvPartial)] // immediate -pub unsafe fn update_inv_partial(component: i32, slots: Vec, objs: Vec) -> Option> { - return Player::write(&UpdateInvPartial::new(component, slots, objs)); -} - -#[wasm_bindgen(js_name = updateInvStopTransmit)] // immediate -pub unsafe fn update_inv_stop_transmit(component: i32) -> Option> { - return Player::write(&UpdateInvStopTransmit::new(component)); -} - -#[wasm_bindgen(js_name = updatePid)] // immediate -pub unsafe fn update_pid(pid: i32) -> Option> { - return Player::write(&UpdatePid::new(pid)); -} - -#[wasm_bindgen(js_name = updateRebootTimer)] // buffered -pub unsafe fn update_reboot_timer(pid: i32, ticks: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&UpdateRebootTimer::new(ticks)), - }; -} - -#[wasm_bindgen(js_name = updateRunEnergy)] // buffered -pub unsafe fn update_runenergy(pid: i32, energy: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&UpdateRunEnergy::new(energy)), - }; -} - -#[wasm_bindgen(js_name = updateRunWeight)] // buffered -pub unsafe fn update_runweight(pid: i32, kg: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&UpdateRunWeight::new(kg)), - }; -} - -#[wasm_bindgen(js_name = updateStat)] // buffered -pub unsafe fn update_stat(pid: i32, stat: i32, experience: i32, level: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.buffer(&UpdateStat::new(stat, experience, level)), - }; -} - -#[wasm_bindgen(js_name = updateZoneFullFollows)] // immediate -pub unsafe fn update_zone_full_follows(x: i32, z: i32, originX: i32, originZ: i32) -> Option> { - return Player::write(&UpdateZoneFullFollows::new(x, z, originX, originZ)); -} - -#[wasm_bindgen(js_name = updateZonePartialEnclosed)] // immediate -pub unsafe fn update_zone_partial_enclosed(x: i32, z: i32, originX: i32, originZ: i32, data: Vec) -> Option> { - return Player::write(&UpdateZonePartialEnclosed::new(x, z, originX, originZ, data)); -} - -#[wasm_bindgen(js_name = updateZonePartialFollows)] // immediate -pub unsafe fn update_zone_partial_follows(x: i32, z: i32, originX: i32, originZ: i32) -> Option> { - return Player::write(&UpdateZonePartialFollows::new(x, z, originX, originZ)); -} - -#[wasm_bindgen(js_name = varp)]// immediate -pub unsafe fn varp(varp: i32, value: i32) -> Option> { - return if value >= -128 && value <= 127 { - Player::write(&VarpSmall::new(varp, value)) - } else { - Player::write(&VarpLarge::new(varp, value)) - } -} - -#[wasm_bindgen(js_name = nextBufferedWrite)] -pub unsafe fn next_buffered_write(pid: i32) -> Option> { - if pid == -1 { - return None; - } - return match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { - None => None, - Some(player) => player.write_queue.pop_front(), - }; -} - -// ---- decoders - -static PACKET_LOOKUP: Lazy>> = Lazy::new(|| { - let mut lookup: Vec> = vec![None; 255]; - lookup[ClientInternalProt::CLIENT_CHEAT as usize] = Some(IncomingPacket::new(ClientProt::CLIENT_CHEAT as i32, ClientCheat::length())); - lookup[ClientInternalProt::CLOSE_MODAL as usize] = Some(IncomingPacket::new(ClientProt::CLOSE_MODAL as i32, CloseModal::length())); - lookup[ClientInternalProt::FRIENDLIST_ADD as usize] = Some(IncomingPacket::new(ClientProt::FRIENDLIST_ADD as i32, FriendListAdd::length())); - lookup[ClientInternalProt::FRIENDLIST_DEL as usize] = Some(IncomingPacket::new(ClientProt::FRIENDLIST_DEL as i32, FriendListDel::length())); - lookup[ClientInternalProt::IDLE_TIMER as usize] = Some(IncomingPacket::new(ClientProt::IDLE_TIMER as i32, IdleTimer::length())); - lookup[ClientInternalProt::IF_BUTTON as usize] = Some(IncomingPacket::new(ClientProt::IF_BUTTON as i32, IfButton::length())); - lookup[ClientInternalProt::IF_PLAYERDESIGN as usize] = Some(IncomingPacket::new(ClientProt::IF_PLAYERDESIGN as i32, IfPlayerDesign::length())); - lookup[ClientInternalProt::IGNORELIST_ADD as usize] = Some(IncomingPacket::new(ClientProt::IGNORELIST_ADD as i32, IgnoreListAdd::length())); - lookup[ClientInternalProt::IGNORELIST_DEL as usize] = Some(IncomingPacket::new(ClientProt::IGNORELIST_DEL as i32, IgnoreListDel::length())); - lookup[ClientInternalProt::INV_BUTTON1 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON1 as i32, InvButton::length())); - lookup[ClientInternalProt::INV_BUTTON2 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON2 as i32, InvButton::length())); - lookup[ClientInternalProt::INV_BUTTON3 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON3 as i32, InvButton::length())); - lookup[ClientInternalProt::INV_BUTTON4 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON4 as i32, InvButton::length())); - lookup[ClientInternalProt::INV_BUTTON5 as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTON5 as i32, InvButton::length())); - lookup[ClientInternalProt::INV_BUTTOND as usize] = Some(IncomingPacket::new(ClientProt::INV_BUTTOND as i32, InvButtonD::length())); - lookup[ClientInternalProt::MESSAGE_PRIVATE as usize] = Some(IncomingPacket::new(ClientProt::MESSAGE_PRIVATE as i32, MessagePrivate::length())); - lookup[ClientInternalProt::MESSAGE_PUBLIC as usize] = Some(IncomingPacket::new(ClientProt::MESSAGE_PUBLIC as i32, MessagePublic::length())); - lookup[ClientInternalProt::MOVE_MINIMAPCLICK as usize] = Some(IncomingPacket::new(ClientProt::MOVE_MINIMAPCLICK as i32, MoveClick::length())); - lookup[ClientInternalProt::MOVE_GAMECLICK as usize] = Some(IncomingPacket::new(ClientProt::MOVE_GAMECLICK as i32, MoveClick::length())); - lookup[ClientInternalProt::MOVE_OPCLICK as usize] = Some(IncomingPacket::new(ClientProt::MOVE_OPCLICK as i32, MoveClick::length())); - lookup[ClientInternalProt::NO_TIMEOUT as usize] = Some(IncomingPacket::new(ClientProt::NO_TIMEOUT as i32, NoTimeout::length())); - lookup[ClientInternalProt::OPHELD1 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD1 as i32, OpHeld::length())); - lookup[ClientInternalProt::OPHELD2 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD2 as i32, OpHeld::length())); - lookup[ClientInternalProt::OPHELD3 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD3 as i32, OpHeld::length())); - lookup[ClientInternalProt::OPHELD4 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD4 as i32, OpHeld::length())); - lookup[ClientInternalProt::OPHELD5 as usize] = Some(IncomingPacket::new(ClientProt::OPHELD5 as i32, OpHeld::length())); - lookup[ClientInternalProt::OPHELDT as usize] = Some(IncomingPacket::new(ClientProt::OPHELDT as i32, OpHeldT::length())); - lookup[ClientInternalProt::OPHELDU as usize] = Some(IncomingPacket::new(ClientProt::OPHELDU as i32, OpHeldU::length())); - lookup[ClientInternalProt::OPLOC1 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC1 as i32, OpLoc::length())); - lookup[ClientInternalProt::OPLOC2 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC2 as i32, OpLoc::length())); - lookup[ClientInternalProt::OPLOC3 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC3 as i32, OpLoc::length())); - lookup[ClientInternalProt::OPLOC4 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC4 as i32, OpLoc::length())); - lookup[ClientInternalProt::OPLOC5 as usize] = Some(IncomingPacket::new(ClientProt::OPLOC5 as i32, OpLoc::length())); - lookup[ClientInternalProt::OPLOCT as usize] = Some(IncomingPacket::new(ClientProt::OPLOCT as i32, OpLocT::length())); - lookup[ClientInternalProt::OPLOCU as usize] = Some(IncomingPacket::new(ClientProt::OPLOCU as i32, OpLocU::length())); - lookup[ClientInternalProt::OPNPC1 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC1 as i32, OpNpc::length())); - lookup[ClientInternalProt::OPNPC2 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC2 as i32, OpNpc::length())); - lookup[ClientInternalProt::OPNPC3 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC3 as i32, OpNpc::length())); - lookup[ClientInternalProt::OPNPC4 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC4 as i32, OpNpc::length())); - lookup[ClientInternalProt::OPNPC5 as usize] = Some(IncomingPacket::new(ClientProt::OPNPC5 as i32, OpNpc::length())); - lookup[ClientInternalProt::OPNPCT as usize] = Some(IncomingPacket::new(ClientProt::OPNPCT as i32, OpNpcT::length())); - lookup[ClientInternalProt::OPNPCU as usize] = Some(IncomingPacket::new(ClientProt::OPNPCU as i32, OpNpcU::length())); - lookup[ClientInternalProt::OPOBJ1 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ1 as i32, OpObj::length())); - lookup[ClientInternalProt::OPOBJ2 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ2 as i32, OpObj::length())); - lookup[ClientInternalProt::OPOBJ3 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ3 as i32, OpObj::length())); - lookup[ClientInternalProt::OPOBJ4 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ4 as i32, OpObj::length())); - lookup[ClientInternalProt::OPOBJ5 as usize] = Some(IncomingPacket::new(ClientProt::OPOBJ5 as i32, OpObj::length())); - lookup[ClientInternalProt::OPOBJT as usize] = Some(IncomingPacket::new(ClientProt::OPOBJT as i32, OpObjT::length())); - lookup[ClientInternalProt::OPOBJU as usize] = Some(IncomingPacket::new(ClientProt::OPOBJU as i32, OpObjU::length())); - lookup[ClientInternalProt::OPPLAYER1 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER1 as i32, OpPlayer::length())); - lookup[ClientInternalProt::OPPLAYER2 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER2 as i32, OpPlayer::length())); - lookup[ClientInternalProt::OPPLAYER3 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER3 as i32, OpPlayer::length())); - lookup[ClientInternalProt::OPPLAYER4 as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYER4 as i32, OpPlayer::length())); - lookup[ClientInternalProt::OPPLAYERT as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYERT as i32, OpPlayerT::length())); - lookup[ClientInternalProt::OPPLAYERU as usize] = Some(IncomingPacket::new(ClientProt::OPPLAYERU as i32, OpPlayerU::length())); - lookup[ClientInternalProt::REBUILD_GETMAPS as usize] = Some(IncomingPacket::new(ClientProt::REBUILD_GETMAPS as i32, RebuildGetMaps::length())); - lookup[ClientInternalProt::RESUME_PAUSEBUTTON as usize] = Some(IncomingPacket::new(ClientProt::RESUME_PAUSEBUTTON as i32, ResumePauseButton::length())); - lookup[ClientInternalProt::RESUME_P_COUNTDIALOG as usize] = Some(IncomingPacket::new(ClientProt::RESUME_P_COUNTDIALOG as i32, ResumePCountDialog::length())); - lookup[ClientInternalProt::TUTORIAL_CLICKSIDE as usize] = Some(IncomingPacket::new(ClientProt::TUTORIAL_CLICKSIDE as i32, TutorialClickSide::length())); - lookup[ClientInternalProt::CHAT_SETMODE as usize] = Some(IncomingPacket::new(ClientProt::CHAT_SETMODE as i32, ChatSetMode::length())); - lookup[ClientInternalProt::EVENT_TRACKING as usize] = Some(IncomingPacket::new(ClientProt::EVENT_TRACKING as i32, EventTracking::length())); - lookup[ClientInternalProt::REPORT_ABUSE as usize] = Some(IncomingPacket::new(ClientProt::REPORT_ABUSE as i32, ReportAbuse::length())); - lookup[ClientInternalProt::EVENT_CAMERA_POSITION as usize] = Some(IncomingPacket::new(ClientProt::EVENT_CAMERA_POSITION as i32, EventCameraPosition::length())); - lookup[ClientInternalProt::ANTICHEAT_OPLOGIC1 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC1 as i32, AnticheatOp1::length())); - lookup[ClientInternalProt::ANTICHEAT_OPLOGIC2 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC2 as i32, AnticheatOp2::length())); - lookup[ClientInternalProt::ANTICHEAT_OPLOGIC3 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC3 as i32, AnticheatOp3::length())); - lookup[ClientInternalProt::ANTICHEAT_OPLOGIC4 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC4 as i32, AnticheatOp4::length())); - lookup[ClientInternalProt::ANTICHEAT_OPLOGIC5 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC5 as i32, AnticheatOp5::length())); - lookup[ClientInternalProt::ANTICHEAT_OPLOGIC6 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC6 as i32, AnticheatOp6::length())); - lookup[ClientInternalProt::ANTICHEAT_OPLOGIC7 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC7 as i32, AnticheatOp7::length())); - lookup[ClientInternalProt::ANTICHEAT_OPLOGIC8 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC8 as i32, AnticheatOp8::length())); - lookup[ClientInternalProt::ANTICHEAT_OPLOGIC9 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_OPLOGIC9 as i32, AnticheatOp9::length())); - lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC1 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC1 as i32, AnticheatCycle1::length())); - lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC2 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC2 as i32, AnticheatCycle2::length())); - lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC3 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC3 as i32, AnticheatCycle3::length())); - lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC4 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC4 as i32, AnticheatCycle4::length())); - lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC5 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC5 as i32, AnticheatCycle5::length())); - lookup[ClientInternalProt::ANTICHEAT_CYCLELOGIC6 as usize] = Some(IncomingPacket::new(ClientProt::ANTICHEAT_CYCLELOGIC6 as i32, AnticheatCycle6::length())); - return lookup; -}); - -#[wasm_bindgen(js_name = nextBufferedRead)] -pub unsafe fn next_buffered_read(id: i32) -> i16 { - return match &*PACKET_LOOKUP.as_ptr().add(id as usize) { - None => -1, - Some(packet) => ((packet.id as i16) << 8) | (packet.length as i16 & 0xff), - } -} - -#[wasm_bindgen(js_name = clientCheat)] -pub unsafe fn clientCheat(bytes: Vec) -> Option { - return Some(ClientCheat::decode(ClientProt::CLIENT_CHEAT, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = closeModal)] -pub unsafe fn close_modal(bytes: Vec) -> Option { - return Some(CloseModal::decode(ClientProt::CLOSE_MODAL, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = friendListAdd)] -pub unsafe fn friend_list_add(bytes: Vec) -> Option { - return Some(FriendListAdd::decode(ClientProt::FRIENDLIST_ADD, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = friendListDel)] -pub unsafe fn friend_list_del(bytes: Vec) -> Option { - return Some(FriendListDel::decode(ClientProt::FRIENDLIST_DEL, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = idleTimer)] -pub unsafe fn idle_timer(bytes: Vec) -> Option { - return Some(IdleTimer::decode(ClientProt::IDLE_TIMER, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = ifButton)] -pub unsafe fn if_button(bytes: Vec) -> Option { - return Some(IfButton::decode(ClientProt::IF_BUTTON, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = ifPlayerDesign)] -pub unsafe fn if_player_design(bytes: Vec) -> Option { - return Some(IfPlayerDesign::decode(ClientProt::IF_PLAYERDESIGN, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = ignoreListAdd)] -pub unsafe fn ignore_list_add(bytes: Vec) -> Option { - return Some(IgnoreListAdd::decode(ClientProt::IGNORELIST_ADD, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = ignoreListDel)] -pub unsafe fn ignore_list_del(bytes: Vec) -> Option { - return Some(IgnoreListDel::decode(ClientProt::IGNORELIST_DEL, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = invButton1)] -pub unsafe fn inv_button1(bytes: Vec) -> Option { - return Some(InvButton::decode(ClientProt::INV_BUTTON1, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = invButton2)] -pub unsafe fn inv_button2(bytes: Vec) -> Option { - return Some(InvButton::decode(ClientProt::INV_BUTTON2, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = invButton3)] -pub unsafe fn inv_button3(bytes: Vec) -> Option { - return Some(InvButton::decode(ClientProt::INV_BUTTON3, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = invButton4)] -pub unsafe fn inv_button4(bytes: Vec) -> Option { - return Some(InvButton::decode(ClientProt::INV_BUTTON4, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = invButton5)] -pub unsafe fn inv_button5(bytes: Vec) -> Option { - return Some(InvButton::decode(ClientProt::INV_BUTTON5, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = invButtonD)] -pub unsafe fn inv_buttonD(bytes: Vec) -> Option { - return Some(InvButtonD::decode(ClientProt::INV_BUTTOND, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = messagePrivate)] -pub unsafe fn message_private(bytes: Vec) -> Option { - return Some(MessagePrivate::decode(ClientProt::MESSAGE_PRIVATE, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = messagePublic)] -pub unsafe fn message_public(bytes: Vec) -> Option { - return Some(MessagePublic::decode(ClientProt::MESSAGE_PUBLIC, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = moveMinimapClick)] -pub unsafe fn move_minimap_click(bytes: Vec) -> Option { - return Some(MoveClick::decode(ClientProt::MOVE_MINIMAPCLICK, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = moveGameClick)] -pub unsafe fn move_game_click(bytes: Vec) -> Option { - return Some(MoveClick::decode(ClientProt::MOVE_GAMECLICK, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = moveOpClick)] -pub unsafe fn move_op_click(bytes: Vec) -> Option { - return Some(MoveClick::decode(ClientProt::MOVE_OPCLICK, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = noTimeout)] -pub unsafe fn no_timeout(bytes: Vec) -> Option { - return Some(NoTimeout::decode(ClientProt::NO_TIMEOUT, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opheld1)] -pub unsafe fn opheld1(bytes: Vec) -> Option { - return Some(OpHeld::decode(ClientProt::OPHELD1, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opheld2)] -pub unsafe fn opheld2(bytes: Vec) -> Option { - return Some(OpHeld::decode(ClientProt::OPHELD2, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opheld3)] -pub unsafe fn opheld3(bytes: Vec) -> Option { - return Some(OpHeld::decode(ClientProt::OPHELD3, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opheld4)] -pub unsafe fn opheld4(bytes: Vec) -> Option { - return Some(OpHeld::decode(ClientProt::OPHELD4, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opheld5)] -pub unsafe fn opheld5(bytes: Vec) -> Option { - return Some(OpHeld::decode(ClientProt::OPHELD5, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opheldT)] -pub unsafe fn opheldT(bytes: Vec) -> Option { - return Some(OpHeldT::decode(ClientProt::OPHELDT, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opheldU)] -pub unsafe fn opheldU(bytes: Vec) -> Option { - return Some(OpHeldU::decode(ClientProt::OPHELDU, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = oploc1)] -pub unsafe fn oploc1(bytes: Vec) -> Option { - return Some(OpLoc::decode(ClientProt::OPLOC1, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = oploc2)] -pub unsafe fn oploc2(bytes: Vec) -> Option { - return Some(OpLoc::decode(ClientProt::OPLOC2, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = oploc3)] -pub unsafe fn oploc3(bytes: Vec) -> Option { - return Some(OpLoc::decode(ClientProt::OPLOC3, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = oploc4)] -pub unsafe fn oploc4(bytes: Vec) -> Option { - return Some(OpLoc::decode(ClientProt::OPLOC4, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = oploc5)] -pub unsafe fn oploc5(bytes: Vec) -> Option { - return Some(OpLoc::decode(ClientProt::OPLOC5, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = oplocT)] -pub unsafe fn oplocT(bytes: Vec) -> Option { - return Some(OpLocT::decode(ClientProt::OPLOCT, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = oplocU)] -pub unsafe fn oplocU(bytes: Vec) -> Option { - return Some(OpLocU::decode(ClientProt::OPLOCU, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opnpc1)] -pub unsafe fn opnpc1(bytes: Vec) -> Option { - return Some(OpNpc::decode(ClientProt::OPNPC1, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opnpc2)] -pub unsafe fn opnpc2(bytes: Vec) -> Option { - return Some(OpNpc::decode(ClientProt::OPNPC2, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opnpc3)] -pub unsafe fn opnpc3(bytes: Vec) -> Option { - return Some(OpNpc::decode(ClientProt::OPNPC3, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opnpc4)] -pub unsafe fn opnpc4(bytes: Vec) -> Option { - return Some(OpNpc::decode(ClientProt::OPNPC4, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opnpc5)] -pub unsafe fn opnpc5(bytes: Vec) -> Option { - return Some(OpNpc::decode(ClientProt::OPNPC5, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opnpcT)] -pub unsafe fn opnpcT(bytes: Vec) -> Option { - return Some(OpNpcT::decode(ClientProt::OPNPCT, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opnpcU)] -pub unsafe fn opnpcU(bytes: Vec) -> Option { - return Some(OpNpcU::decode(ClientProt::OPNPCU, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opobj1)] -pub unsafe fn opobj1(bytes: Vec) -> Option { - return Some(OpObj::decode(ClientProt::OPOBJ1, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opobj2)] -pub unsafe fn opobj2(bytes: Vec) -> Option { - return Some(OpObj::decode(ClientProt::OPOBJ2, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opobj3)] -pub unsafe fn opobj3(bytes: Vec) -> Option { - return Some(OpObj::decode(ClientProt::OPOBJ3, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opobj4)] -pub unsafe fn opobj4(bytes: Vec) -> Option { - return Some(OpObj::decode(ClientProt::OPOBJ4, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opobj5)] -pub unsafe fn opobj5(bytes: Vec) -> Option { - return Some(OpObj::decode(ClientProt::OPOBJ5, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opobjT)] -pub unsafe fn opobjT(bytes: Vec) -> Option { - return Some(OpObjT::decode(ClientProt::OPOBJT, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opobjU)] -pub unsafe fn opobjU(bytes: Vec) -> Option { - return Some(OpObjU::decode(ClientProt::OPOBJU, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opplayer1)] -pub unsafe fn opplayer1(bytes: Vec) -> Option { - return Some(OpPlayer::decode(ClientProt::OPPLAYER1, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opplayer2)] -pub unsafe fn opplayer2(bytes: Vec) -> Option { - return Some(OpPlayer::decode(ClientProt::OPPLAYER2, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opplayer3)] -pub unsafe fn opplayer3(bytes: Vec) -> Option { - return Some(OpPlayer::decode(ClientProt::OPPLAYER3, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opplayer4)] -pub unsafe fn opplayer4(bytes: Vec) -> Option { - return Some(OpPlayer::decode(ClientProt::OPPLAYER4, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opplayerT)] -pub unsafe fn opplayerT(bytes: Vec) -> Option { - return Some(OpPlayerT::decode(ClientProt::OPPLAYERT, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = opplayerU)] -pub unsafe fn opplayerU(bytes: Vec) -> Option { - return Some(OpPlayerU::decode(ClientProt::OPPLAYERU, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = rebuildGetMaps)] -pub unsafe fn rebuild_getmaps(bytes: Vec) -> Option { - return Some(RebuildGetMaps::decode(ClientProt::REBUILD_GETMAPS, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = resumePauseButton)] -pub unsafe fn resume_pausebutton(bytes: Vec) -> Option { - return Some(ResumePauseButton::decode(ClientProt::RESUME_PAUSEBUTTON, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = resumeCountDialog)] -pub unsafe fn resume_countdialog(bytes: Vec) -> Option { - return Some(ResumePCountDialog::decode(ClientProt::RESUME_P_COUNTDIALOG, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = tutorialClickSide)] -pub unsafe fn tutorial_clickside(bytes: Vec) -> Option { - return Some(TutorialClickSide::decode(ClientProt::TUTORIAL_CLICKSIDE, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = chatSetMode)] -pub unsafe fn chat_setmode(bytes: Vec) -> Option { - return Some(ChatSetMode::decode(ClientProt::CHAT_SETMODE, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = eventTracking)] -pub unsafe fn event_tracking(bytes: Vec) -> Option { - return Some(EventTracking::decode(ClientProt::EVENT_TRACKING, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = reportAbuse)] -pub unsafe fn report_abuse(bytes: Vec) -> Option { - return Some(ReportAbuse::decode(ClientProt::REPORT_ABUSE, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = eventCameraPosition)] -pub unsafe fn event_camera_position(bytes: Vec) -> Option { - return Some(EventCameraPosition::decode(ClientProt::EVENT_CAMERA_POSITION, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatOp1)] -pub unsafe fn anticheatop1(bytes: Vec) -> Option { - return Some(AnticheatOp1::decode(ClientProt::ANTICHEAT_OPLOGIC1, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatOp2)] -pub unsafe fn anticheatop2(bytes: Vec) -> Option { - return Some(AnticheatOp2::decode(ClientProt::ANTICHEAT_OPLOGIC2, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatOp3)] -pub unsafe fn anticheatop3(bytes: Vec) -> Option { - return Some(AnticheatOp3::decode(ClientProt::ANTICHEAT_OPLOGIC3, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatOp4)] -pub unsafe fn anticheatop4(bytes: Vec) -> Option { - return Some(AnticheatOp4::decode(ClientProt::ANTICHEAT_OPLOGIC4, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatOp5)] -pub unsafe fn anticheatop5(bytes: Vec) -> Option { - return Some(AnticheatOp5::decode(ClientProt::ANTICHEAT_OPLOGIC5, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatOp6)] -pub unsafe fn anticheatop6(bytes: Vec) -> Option { - return Some(AnticheatOp6::decode(ClientProt::ANTICHEAT_OPLOGIC6, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatOp7)] -pub unsafe fn anticheatop7(bytes: Vec) -> Option { - return Some(AnticheatOp7::decode(ClientProt::ANTICHEAT_OPLOGIC7, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatOp8)] -pub unsafe fn anticheatop8(bytes: Vec) -> Option { - return Some(AnticheatOp8::decode(ClientProt::ANTICHEAT_OPLOGIC8, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatOp9)] -pub unsafe fn anticheatop9(bytes: Vec) -> Option { - return Some(AnticheatOp9::decode(ClientProt::ANTICHEAT_OPLOGIC9, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatCycle1)] -pub unsafe fn anticheatcycle1(bytes: Vec) -> Option { - return Some(AnticheatCycle1::decode(ClientProt::ANTICHEAT_CYCLELOGIC1, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatCycle2)] -pub unsafe fn anticheatcycle2(bytes: Vec) -> Option { - return Some(AnticheatCycle2::decode(ClientProt::ANTICHEAT_CYCLELOGIC2, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatCycle3)] -pub unsafe fn anticheatcycle3(bytes: Vec) -> Option { - return Some(AnticheatCycle3::decode(ClientProt::ANTICHEAT_CYCLELOGIC3, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatCycle4)] -pub unsafe fn anticheatcycle4(bytes: Vec) -> Option { - return Some(AnticheatCycle4::decode(ClientProt::ANTICHEAT_CYCLELOGIC4, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatCycle5)] -pub unsafe fn anticheatcycle5(bytes: Vec) -> Option { - return Some(AnticheatCycle5::decode(ClientProt::ANTICHEAT_CYCLELOGIC5, Packet::from(bytes))); -} - -#[wasm_bindgen(js_name = anticheatCycle6)] -pub unsafe fn anticheatcycle6(bytes: Vec) -> Option { - return Some(AnticheatCycle6::decode(ClientProt::ANTICHEAT_CYCLELOGIC6, Packet::from(bytes))); -} - -// ---- misc - #[wasm_bindgen(js_name = unpackWords)] pub unsafe fn unpack_words(bytes: Vec, length: usize) -> String { return WORD_PACK.unpack(Packet::from(bytes), length); diff --git a/src/out/npc_info.rs b/src/out/npc_info.rs index 97c058d..bf66703 100644 --- a/src/out/npc_info.rs +++ b/src/out/npc_info.rs @@ -30,7 +30,6 @@ impl NpcInfo { #[inline] pub fn encode( &mut self, - pos: usize, renderer: &mut NpcRenderer, npcs: &mut [Option], map: &mut ZoneMap, @@ -51,7 +50,7 @@ impl NpcInfo { self.updates.bit_pos = 0; self.buf.bits(); - let bytes: usize = self.write_npcs(npcs, renderer, player, pos); + let bytes: usize = self.write_npcs(npcs, renderer, player, 0); self.write_new_npcs(map, npcs, renderer, player, bytes); if self.updates.pos > 0 { self.buf.pbit(13, 8191); diff --git a/src/out/player_info.rs b/src/out/player_info.rs index 8376e91..737d397 100644 --- a/src/out/player_info.rs +++ b/src/out/player_info.rs @@ -31,7 +31,6 @@ impl PlayerInfo { #[inline] pub fn encode( &mut self, - pos: usize, renderer: &mut PlayerRenderer, players: &[Option], map: &mut ZoneMap, @@ -56,7 +55,7 @@ impl PlayerInfo { self.buf.bits(); let bytes1: usize = self.write_local_player(renderer, player); - let bytes2: usize = self.write_players(players, renderer, player, bytes1 + pos); + let bytes2: usize = self.write_players(players, renderer, player, bytes1); self.write_new_players(map, players, renderer, grid, player, bytes2); if self.updates.pos > 0 { self.buf.pbit(11, 2047); diff --git a/src/player.rs b/src/player.rs index 1aec5dd..e05d18f 100644 --- a/src/player.rs +++ b/src/player.rs @@ -99,12 +99,12 @@ impl Player { #[inline] pub fn buffer(&mut self, message: &dyn MessageEncoder) -> Option> { - self.write_queue.push_back(Player::write(message).unwrap()); + self.write_queue.push_back(Player::write(message)); return None; } #[inline] - pub fn write(message: &dyn MessageEncoder) -> Option> { + pub fn write(message: &dyn MessageEncoder) -> Vec { let id: i32 = message.id(); let offset: usize = match message.length() { -1 => 1 + 1, @@ -118,14 +118,14 @@ impl Player { -2 => buf.pos += 2, _ => {} }; - let start = buf.pos; + let start: usize = buf.pos; message.encode(&mut buf); match message.length() { -1 => buf.psize1((buf.pos - start) as u8), -2 => buf.psize2((buf.pos - start) as u16), _ => {} }; - return Some(buf.data); + return buf.data; } #[inline] From 43c62c6a82d7b8019b8d401f356f82129cf3b23c Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 31 Mar 2025 19:14:42 -0400 Subject: [PATCH 07/14] feat: cleanup --- src/lib.rs | 16 +++++++++----- src/message.rs | 28 ------------------------- src/out/cam_lookat.rs | 6 ------ src/out/cam_moveto.rs | 6 ------ src/out/cam_reset.rs | 6 ------ src/out/cam_shake.rs | 6 ------ src/out/chat_filter_settings.rs | 6 ------ src/out/count_dialog.rs | 6 ------ src/out/data_land.rs | 11 ---------- src/out/data_loc.rs | 11 ---------- src/out/enable_tracking.rs | 6 ------ src/out/finish_tracking.rs | 6 ------ src/out/hint_arrow.rs | 6 ------ src/out/if_close.rs | 6 ------ src/out/if_openchat.rs | 6 ------ src/out/if_openmain.rs | 6 ------ src/out/if_openmainside.rs | 6 ------ src/out/if_openside.rs | 6 ------ src/out/if_setanim.rs | 6 ------ src/out/if_setcolour.rs | 6 ------ src/out/if_sethide.rs | 6 ------ src/out/if_setmodel.rs | 6 ------ src/out/if_setnpchead.rs | 6 ------ src/out/if_setobject.rs | 6 ------ src/out/if_setplayerhead.rs | 6 ------ src/out/if_setposition.rs | 6 ------ src/out/if_setrecol.rs | 6 ------ src/out/if_settab.rs | 6 ------ src/out/if_settabactive.rs | 6 ------ src/out/if_settext.rs | 6 ------ src/out/last_login_info.rs | 6 ------ src/out/loc_addchange.rs | 6 ------ src/out/loc_anim.rs | 6 ------ src/out/loc_del.rs | 6 ------ src/out/loc_merge.rs | 6 ------ src/out/logout.rs | 6 ------ src/out/map_anim.rs | 6 ------ src/out/map_projanim.rs | 6 ------ src/out/message_game.rs | 6 ------ src/out/message_private.rs | 6 ------ src/out/midi_jingle.rs | 6 ------ src/out/midi_song.rs | 6 ------ src/out/obj_add.rs | 6 ------ src/out/obj_count.rs | 6 ------ src/out/obj_del.rs | 6 ------ src/out/obj_reveal.rs | 6 ------ src/out/rebuild_normal.rs | 6 ------ src/out/reset_anims.rs | 6 ------ src/out/reset_clientvarcache.rs | 6 ------ src/out/set_multiway.rs | 6 ------ src/out/synth_sound.rs | 6 ------ src/out/tut_flash.rs | 6 ------ src/out/tut_open.rs | 6 ------ src/out/unset_map_flag.rs | 6 ------ src/out/update_friendlist.rs | 6 ------ src/out/update_ignorelist.rs | 6 ------ src/out/update_inv_full.rs | 6 ------ src/out/update_inv_partial.rs | 6 ------ src/out/update_inv_stop_transmit.rs | 6 ------ src/out/update_pid.rs | 6 ------ src/out/update_reboot_timer.rs | 6 ------ src/out/update_runenergy.rs | 6 ------ src/out/update_runweight.rs | 6 ------ src/out/update_stat.rs | 6 ------ src/out/update_zone_full_follows.rs | 6 ------ src/out/update_zone_partial_enclosed.rs | 6 ------ src/out/update_zone_partial_follows.rs | 6 ------ src/out/varp_large.rs | 6 ------ src/out/varp_small.rs | 6 ------ src/priority.rs | 12 ----------- 70 files changed, 11 insertions(+), 457 deletions(-) delete mode 100644 src/priority.rs diff --git a/src/lib.rs b/src/lib.rs index 6939504..6552df6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -120,7 +120,6 @@ mod message; mod grid; mod npc; mod visibility; -mod priority; mod category; mod r#in; mod out; @@ -135,6 +134,11 @@ macro_rules! read { }; } +// these priorities are important for cases where the content developer wants to be aware of the +// bandwidth implications their script may run into and how it impacts the player experience + +// counted as part of the buffer_full command +// alternate names: LOW, CONTENT macro_rules! buffer { ($fn_name:ident, $js_name:literal, $struct:ty, ($($arg_name:ident: $arg_ty:ty),*), ($($arg_val:ident),*)) => { #[wasm_bindgen(js_name = $js_name)] @@ -150,6 +154,8 @@ macro_rules! buffer { }; } +// not counted as part of the buffer_full command +// alternate names: HIGH, ESSENTIAL, ENGINE macro_rules! write { ($fn_name:ident, $js_name:literal, $struct:ty, ($($arg_name:ident: $arg_ty:ty),*), ($($arg_val:ident),*)) => { #[wasm_bindgen(js_name = $js_name)] @@ -533,7 +539,7 @@ write!(data_loc, "dataLoc", DataLoc, (x: i32, z: i32, offset: i32, length: i32, write!(data_loc_done, "dataLocDone", DataLocDone, (x: i32, z: i32), (x, z)); buffer!(enable_tracking, "enableTracking", EnableTracking, (), ()); buffer!(finish_tracking, "finishTracking", FinishTracking, (), ()); -buffer!(hint_arrow, "hintArrow", HintArrow, (arrow: i32, nid: i32, pid2: i32, x: i32, z: i32, y: i32), (arrow, nid, pid2, x, z, y)); +buffer!(hint_arrow, "hintArrow", HintArrow, (arrow: i32, nid: i32, pid2: i32, x: i32, z: i32, y: i32), (arrow, nid, pid2, x, z, y)); // todo: what should priority be? buffer!(if_close, "ifClose", IfClose, (), ()); buffer!(if_open_chat, "ifOpenChat", IfOpenChat, (component: i32), (component)); buffer!(if_open_main, "ifOpenMain", IfOpenMain, (component: i32), (component)); @@ -568,7 +574,7 @@ write!(obj_count, "objCount", ObjCount, (coord: i32, obj: i32, oldCount: i32, ne write!(obj_del, "objDel", ObjDel, (coord: i32, obj: i32), (coord, obj)); write!(obj_reveal, "objReveal", ObjReveal, (coord: i32, obj: i32, count: i32, receiver: i32), (coord, obj, count, receiver)); write!(rebuild_normal, "rebuildNormal", RebuildNormal, (x: i32, z: i32, squares: Vec, maps: Vec, locs: Vec), (x, z, squares, maps, locs)); -write!(reset_anims, "resetAnims", ResetAnims, (), ()); +write!(reset_anims, "resetAnims", ResetAnims, (), ()); // todo: what should priority be? write!(reset_clientvarcache, "resetClientVarCache", ResetClientVarCache, (), ()); buffer!(set_multiway, "setMultiway", SetMultiway, (hidden: bool), (hidden)); buffer!(synth_sound, "synthSound", SynthSound, (synth: i32, loops: i32, delay: i32), (synth, loops, delay)); @@ -580,8 +586,8 @@ buffer!(update_ignorelist, "updateIgnoreList", UpdateIgnoreList, (names: Vec), (size, component, objs)); write!(update_inv_partial, "updateInvPartial", UpdateInvPartial, (component: i32, slots: Vec, objs: Vec), (component, slots, objs)); write!(update_inv_stop_transmit, "updateInvStopTransmit", UpdateInvStopTransmit, (component: i32), (component)); -write!(update_pid, "updatePid", UpdatePid, (pid: i32), (pid)); -buffer!(update_reboot_timer, "updateRebootTimer", UpdateRebootTimer, (ticks: i32), (ticks)); +write!(update_pid, "updatePid", UpdatePid, (pid: i32), (pid)); // todo: what should priority be? +buffer!(update_reboot_timer, "updateRebootTimer", UpdateRebootTimer, (ticks: i32), (ticks)); // todo: what should priority be? buffer!(update_runenergy, "updateRunEnergy", UpdateRunEnergy, (energy: i32), (energy)); buffer!(update_runweight, "updateRunWeight", UpdateRunWeight, (kg: i32), (kg)); buffer!(update_stat, "updateStat", UpdateStat, (stat: i32, experience: i32, level: i32), (stat, experience, level)); diff --git a/src/message.rs b/src/message.rs index 24e9527..02772db 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,5 +1,4 @@ use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ClientProt; pub trait InfoMessage { @@ -10,7 +9,6 @@ pub trait InfoMessage { pub trait MessageEncoder { fn id(&self) -> i32; fn length(&self) -> i32; - fn priority(&self) -> ServerProtPriority; fn encode(&self, buf: &mut Packet); fn test(&self) -> usize; } @@ -20,32 +18,6 @@ pub trait MessageDecoder { fn decode(prot: ClientProt, buf: Packet) -> T; } -// #[wasm_bindgen] -// #[derive(Clone)] -// pub struct OutgoingPacket { -// #[wasm_bindgen(getter_with_clone, readonly)] -// pub bytes: Option>, -// #[wasm_bindgen(readonly)] -// pub id: i32, -// #[wasm_bindgen(readonly)] -// pub length: i32, -// } -// -// impl OutgoingPacket { -// #[inline] -// pub fn new( -// bytes: Option>, -// id: i32, -// length: i32 -// ) -> OutgoingPacket { -// return OutgoingPacket { -// bytes, -// id, -// length, -// } -// } -// } - #[derive(Clone)] pub struct IncomingPacket { pub id: i32, diff --git a/src/out/cam_lookat.rs b/src/out/cam_lookat.rs index 18e8d91..16d9b82 100644 --- a/src/out/cam_lookat.rs +++ b/src/out/cam_lookat.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct CamLookAt { @@ -41,11 +40,6 @@ impl MessageEncoder for CamLookAt { return 6; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); diff --git a/src/out/cam_moveto.rs b/src/out/cam_moveto.rs index 75af2a8..686b7a0 100644 --- a/src/out/cam_moveto.rs +++ b/src/out/cam_moveto.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct CamMoveTo { @@ -41,11 +40,6 @@ impl MessageEncoder for CamMoveTo { return 6; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); diff --git a/src/out/cam_reset.rs b/src/out/cam_reset.rs index 36a8c7c..d1a23b3 100644 --- a/src/out/cam_reset.rs +++ b/src/out/cam_reset.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct CamReset {} @@ -23,11 +22,6 @@ impl MessageEncoder for CamReset { return 0; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, _: &mut Packet) {} diff --git a/src/out/cam_shake.rs b/src/out/cam_shake.rs index 4f0024d..69ca249 100644 --- a/src/out/cam_shake.rs +++ b/src/out/cam_shake.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct CamShake { @@ -38,11 +37,6 @@ impl MessageEncoder for CamShake { return 4; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.shake); // direction? diff --git a/src/out/chat_filter_settings.rs b/src/out/chat_filter_settings.rs index cf274cf..6901b42 100644 --- a/src/out/chat_filter_settings.rs +++ b/src/out/chat_filter_settings.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct ChatFilterSettings { @@ -35,11 +34,6 @@ impl MessageEncoder for ChatFilterSettings { return 3; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.public); diff --git a/src/out/count_dialog.rs b/src/out/count_dialog.rs index e166133..70dd93a 100644 --- a/src/out/count_dialog.rs +++ b/src/out/count_dialog.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct PCountDialog {} @@ -23,11 +22,6 @@ impl MessageEncoder for PCountDialog { return 0; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, _: &mut Packet) {} diff --git a/src/out/data_land.rs b/src/out/data_land.rs index 8eb5c8b..c708419 100644 --- a/src/out/data_land.rs +++ b/src/out/data_land.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct DataLand { @@ -41,11 +40,6 @@ impl MessageEncoder for DataLand { return -2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); @@ -92,11 +86,6 @@ impl MessageEncoder for DataLandDone { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); diff --git a/src/out/data_loc.rs b/src/out/data_loc.rs index 31b2db9..07ab8ac 100644 --- a/src/out/data_loc.rs +++ b/src/out/data_loc.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct DataLoc { @@ -41,11 +40,6 @@ impl MessageEncoder for DataLoc { return -2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); @@ -92,11 +86,6 @@ impl MessageEncoder for DataLocDone { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.x); diff --git a/src/out/enable_tracking.rs b/src/out/enable_tracking.rs index 4d20d4c..e11fe95 100644 --- a/src/out/enable_tracking.rs +++ b/src/out/enable_tracking.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct EnableTracking {} @@ -23,11 +22,6 @@ impl MessageEncoder for EnableTracking { return 0; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, _: &mut Packet) {} diff --git a/src/out/finish_tracking.rs b/src/out/finish_tracking.rs index ee9c995..441975f 100644 --- a/src/out/finish_tracking.rs +++ b/src/out/finish_tracking.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct FinishTracking {} @@ -23,11 +22,6 @@ impl MessageEncoder for FinishTracking { return 0; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, _: &mut Packet) {} diff --git a/src/out/hint_arrow.rs b/src/out/hint_arrow.rs index 9268e24..a90b9e4 100644 --- a/src/out/hint_arrow.rs +++ b/src/out/hint_arrow.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct HintArrow { @@ -44,11 +43,6 @@ impl MessageEncoder for HintArrow { return 6; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; // todo: what should priority be? - } - #[inline] fn encode(&self, buf: &mut Packet) { match self.arrow { diff --git a/src/out/if_close.rs b/src/out/if_close.rs index f4d2dcd..957d9c5 100644 --- a/src/out/if_close.rs +++ b/src/out/if_close.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfClose {} @@ -23,11 +22,6 @@ impl MessageEncoder for IfClose { return 0; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, _: &mut Packet) {} diff --git a/src/out/if_openchat.rs b/src/out/if_openchat.rs index 1ab28d7..f859f08 100644 --- a/src/out/if_openchat.rs +++ b/src/out/if_openchat.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfOpenChat { @@ -27,11 +26,6 @@ impl MessageEncoder for IfOpenChat { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_openmain.rs b/src/out/if_openmain.rs index c72e3f4..aaba0ff 100644 --- a/src/out/if_openmain.rs +++ b/src/out/if_openmain.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfOpenMain { @@ -27,11 +26,6 @@ impl MessageEncoder for IfOpenMain { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_openmainside.rs b/src/out/if_openmainside.rs index 2a0eddf..0588ab4 100644 --- a/src/out/if_openmainside.rs +++ b/src/out/if_openmainside.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfOpenMainSide { @@ -32,11 +31,6 @@ impl MessageEncoder for IfOpenMainSide { return 4; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.main); diff --git a/src/out/if_openside.rs b/src/out/if_openside.rs index dad5330..0c2f58d 100644 --- a/src/out/if_openside.rs +++ b/src/out/if_openside.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfOpenSide { @@ -27,11 +26,6 @@ impl MessageEncoder for IfOpenSide { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_setanim.rs b/src/out/if_setanim.rs index d9b32be..ca6b9cb 100644 --- a/src/out/if_setanim.rs +++ b/src/out/if_setanim.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetAnim { @@ -32,11 +31,6 @@ impl MessageEncoder for IfSetAnim { return 4; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_setcolour.rs b/src/out/if_setcolour.rs index d9760d3..1c2b1c2 100644 --- a/src/out/if_setcolour.rs +++ b/src/out/if_setcolour.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetColour { @@ -32,11 +31,6 @@ impl MessageEncoder for IfSetColour { return 4; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_sethide.rs b/src/out/if_sethide.rs index cf43d8c..7e18f32 100644 --- a/src/out/if_sethide.rs +++ b/src/out/if_sethide.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetHide { @@ -32,11 +31,6 @@ impl MessageEncoder for IfSetHide { return 3; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_setmodel.rs b/src/out/if_setmodel.rs index 516f0a0..8f5c13f 100644 --- a/src/out/if_setmodel.rs +++ b/src/out/if_setmodel.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetModel { @@ -32,11 +31,6 @@ impl MessageEncoder for IfSetModel { return 4; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_setnpchead.rs b/src/out/if_setnpchead.rs index 4c2155c..2d4e517 100644 --- a/src/out/if_setnpchead.rs +++ b/src/out/if_setnpchead.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetNpcHead { @@ -32,11 +31,6 @@ impl MessageEncoder for IfSetNpcHead { return 4; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_setobject.rs b/src/out/if_setobject.rs index d59006a..e374d8e 100644 --- a/src/out/if_setobject.rs +++ b/src/out/if_setobject.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetObject { @@ -35,11 +34,6 @@ impl MessageEncoder for IfSetObject { return 6; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_setplayerhead.rs b/src/out/if_setplayerhead.rs index bbc2d6c..ed5569a 100644 --- a/src/out/if_setplayerhead.rs +++ b/src/out/if_setplayerhead.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetPlayerHead { @@ -29,11 +28,6 @@ impl MessageEncoder for IfSetPlayerHead { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_setposition.rs b/src/out/if_setposition.rs index 07cddc5..8230f50 100644 --- a/src/out/if_setposition.rs +++ b/src/out/if_setposition.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetPosition { @@ -35,11 +34,6 @@ impl MessageEncoder for IfSetPosition { return 6; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_setrecol.rs b/src/out/if_setrecol.rs index f44d6b6..2b391ab 100644 --- a/src/out/if_setrecol.rs +++ b/src/out/if_setrecol.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetRecol { @@ -35,11 +34,6 @@ impl MessageEncoder for IfSetRecol { return 6; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_settab.rs b/src/out/if_settab.rs index dd5fef3..b285d6e 100644 --- a/src/out/if_settab.rs +++ b/src/out/if_settab.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetTab { @@ -32,11 +31,6 @@ impl MessageEncoder for IfSetTab { return 3; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/if_settabactive.rs b/src/out/if_settabactive.rs index 4511244..fd4da37 100644 --- a/src/out/if_settabactive.rs +++ b/src/out/if_settabactive.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetTabActive { @@ -29,11 +28,6 @@ impl MessageEncoder for IfSetTabActive { return 1; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.tab); diff --git a/src/out/if_settext.rs b/src/out/if_settext.rs index 87b22b3..fb9c566 100644 --- a/src/out/if_settext.rs +++ b/src/out/if_settext.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct IfSetText { @@ -32,11 +31,6 @@ impl MessageEncoder for IfSetText { return -2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/last_login_info.rs b/src/out/last_login_info.rs index c5998b3..025bdac 100644 --- a/src/out/last_login_info.rs +++ b/src/out/last_login_info.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct LastLoginInfo { @@ -38,11 +37,6 @@ impl MessageEncoder for LastLoginInfo { return 9; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p4(self.last_ip); diff --git a/src/out/loc_addchange.rs b/src/out/loc_addchange.rs index af9e373..549148c 100644 --- a/src/out/loc_addchange.rs +++ b/src/out/loc_addchange.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct LocAddChange { @@ -38,11 +37,6 @@ impl MessageEncoder for LocAddChange { return 4; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); diff --git a/src/out/loc_anim.rs b/src/out/loc_anim.rs index 7024177..188a423 100644 --- a/src/out/loc_anim.rs +++ b/src/out/loc_anim.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct LocAnim { @@ -38,11 +37,6 @@ impl MessageEncoder for LocAnim { return 4; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); diff --git a/src/out/loc_del.rs b/src/out/loc_del.rs index a455dc4..0422bc6 100644 --- a/src/out/loc_del.rs +++ b/src/out/loc_del.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct LocDel { @@ -35,11 +34,6 @@ impl MessageEncoder for LocDel { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); diff --git a/src/out/loc_merge.rs b/src/out/loc_merge.rs index 79d3160..8cc91d7 100644 --- a/src/out/loc_merge.rs +++ b/src/out/loc_merge.rs @@ -1,7 +1,6 @@ use crate::coord::CoordGrid; use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct LocMerge { @@ -64,11 +63,6 @@ impl MessageEncoder for LocMerge { fn length(&self) -> i32 { return 14; } - - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } #[inline] fn encode(&self, buf: &mut Packet) { diff --git a/src/out/logout.rs b/src/out/logout.rs index c3f3b60..4cbd828 100644 --- a/src/out/logout.rs +++ b/src/out/logout.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct Logout {} @@ -23,11 +22,6 @@ impl MessageEncoder for Logout { return 0; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, _: &mut Packet) {} diff --git a/src/out/map_anim.rs b/src/out/map_anim.rs index 9b457a2..2ff4583 100644 --- a/src/out/map_anim.rs +++ b/src/out/map_anim.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct MapAnim { @@ -38,11 +37,6 @@ impl MessageEncoder for MapAnim { return 6; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); diff --git a/src/out/map_projanim.rs b/src/out/map_projanim.rs index 8622165..4402b0d 100644 --- a/src/out/map_projanim.rs +++ b/src/out/map_projanim.rs @@ -1,7 +1,6 @@ use crate::coord::CoordGrid; use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct MapProjAnim { @@ -65,11 +64,6 @@ impl MessageEncoder for MapProjAnim { return 15; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); diff --git a/src/out/message_game.rs b/src/out/message_game.rs index e10c564..b80507c 100644 --- a/src/out/message_game.rs +++ b/src/out/message_game.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct MessageGame { @@ -27,11 +26,6 @@ impl MessageEncoder for MessageGame { return -1; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.pjstr(&self.msg, 10); diff --git a/src/out/message_private.rs b/src/out/message_private.rs index 8c49e5c..b5d690d 100644 --- a/src/out/message_private.rs +++ b/src/out/message_private.rs @@ -1,7 +1,6 @@ use crate::message::MessageEncoder; use crate::pack::WordPack; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct MessagePrivateOut { @@ -39,11 +38,6 @@ impl MessageEncoder for MessagePrivateOut { return -1; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { let mut staff_mod_level = self.staff_mod_level; diff --git a/src/out/midi_jingle.rs b/src/out/midi_jingle.rs index b64177c..d35e3c8 100644 --- a/src/out/midi_jingle.rs +++ b/src/out/midi_jingle.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct MidiJingle { @@ -32,11 +31,6 @@ impl MessageEncoder for MidiJingle { return -2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.delay); diff --git a/src/out/midi_song.rs b/src/out/midi_song.rs index cd2f495..34a3933 100644 --- a/src/out/midi_song.rs +++ b/src/out/midi_song.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct MidiSong { @@ -35,11 +34,6 @@ impl MessageEncoder for MidiSong { return -1; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.pjstr(&self.name, 10); diff --git a/src/out/obj_add.rs b/src/out/obj_add.rs index f1f50d1..4a8b899 100644 --- a/src/out/obj_add.rs +++ b/src/out/obj_add.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct ObjAdd { @@ -35,11 +34,6 @@ impl MessageEncoder for ObjAdd { return 5; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); diff --git a/src/out/obj_count.rs b/src/out/obj_count.rs index 7471683..d35131f 100644 --- a/src/out/obj_count.rs +++ b/src/out/obj_count.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct ObjCount { @@ -38,11 +37,6 @@ impl MessageEncoder for ObjCount { return 7; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); diff --git a/src/out/obj_del.rs b/src/out/obj_del.rs index e241ff0..1f76e93 100644 --- a/src/out/obj_del.rs +++ b/src/out/obj_del.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct ObjDel { @@ -32,11 +31,6 @@ impl MessageEncoder for ObjDel { return 3; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); diff --git a/src/out/obj_reveal.rs b/src/out/obj_reveal.rs index 4d7aa11..64176fd 100644 --- a/src/out/obj_reveal.rs +++ b/src/out/obj_reveal.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct ObjReveal { @@ -38,11 +37,6 @@ impl MessageEncoder for ObjReveal { return 7; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.coord); diff --git a/src/out/rebuild_normal.rs b/src/out/rebuild_normal.rs index c0bb62b..32f7015 100644 --- a/src/out/rebuild_normal.rs +++ b/src/out/rebuild_normal.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct RebuildNormal { @@ -41,11 +40,6 @@ impl MessageEncoder for RebuildNormal { return -2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.x); diff --git a/src/out/reset_anims.rs b/src/out/reset_anims.rs index f94a3d9..e0ed856 100644 --- a/src/out/reset_anims.rs +++ b/src/out/reset_anims.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct ResetAnims {} @@ -23,11 +22,6 @@ impl MessageEncoder for ResetAnims { return 0; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; // todo: what should priority be? - } - #[inline] fn encode(&self, _: &mut Packet) {} diff --git a/src/out/reset_clientvarcache.rs b/src/out/reset_clientvarcache.rs index a626aa0..126ea43 100644 --- a/src/out/reset_clientvarcache.rs +++ b/src/out/reset_clientvarcache.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct ResetClientVarCache {} @@ -23,11 +22,6 @@ impl MessageEncoder for ResetClientVarCache { return 0; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, _: &mut Packet) {} diff --git a/src/out/set_multiway.rs b/src/out/set_multiway.rs index bf8878f..43a9e95 100644 --- a/src/out/set_multiway.rs +++ b/src/out/set_multiway.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct SetMultiway { @@ -27,11 +26,6 @@ impl MessageEncoder for SetMultiway { return 1; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(if self.hidden { 1 } else { 0 }); diff --git a/src/out/synth_sound.rs b/src/out/synth_sound.rs index 7df68e4..a9d0bd1 100644 --- a/src/out/synth_sound.rs +++ b/src/out/synth_sound.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct SynthSound { @@ -35,11 +34,6 @@ impl MessageEncoder for SynthSound { return 5; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.synth); diff --git a/src/out/tut_flash.rs b/src/out/tut_flash.rs index 9e30979..73570b4 100644 --- a/src/out/tut_flash.rs +++ b/src/out/tut_flash.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct TutFlash { @@ -29,11 +28,6 @@ impl MessageEncoder for TutFlash { return 1; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.tab); diff --git a/src/out/tut_open.rs b/src/out/tut_open.rs index de19378..fceead9 100644 --- a/src/out/tut_open.rs +++ b/src/out/tut_open.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct TutOpen { @@ -29,11 +28,6 @@ impl MessageEncoder for TutOpen { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/unset_map_flag.rs b/src/out/unset_map_flag.rs index c390936..1127e37 100644 --- a/src/out/unset_map_flag.rs +++ b/src/out/unset_map_flag.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UnsetMapFlag {} @@ -23,11 +22,6 @@ impl MessageEncoder for UnsetMapFlag { return 0; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, _: &mut Packet) {} diff --git a/src/out/update_friendlist.rs b/src/out/update_friendlist.rs index 036df80..8a6f99d 100644 --- a/src/out/update_friendlist.rs +++ b/src/out/update_friendlist.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateFriendList { @@ -29,11 +28,6 @@ impl MessageEncoder for UpdateFriendList { return 9; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p8(self.name); diff --git a/src/out/update_ignorelist.rs b/src/out/update_ignorelist.rs index 1ded27d..fac1fc0 100644 --- a/src/out/update_ignorelist.rs +++ b/src/out/update_ignorelist.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateIgnoreList { @@ -27,11 +26,6 @@ impl MessageEncoder for UpdateIgnoreList { return -2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { for &name in self.names.iter() { diff --git a/src/out/update_inv_full.rs b/src/out/update_inv_full.rs index 6a2ef27..6ab706c 100644 --- a/src/out/update_inv_full.rs +++ b/src/out/update_inv_full.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateInvFull { @@ -35,11 +34,6 @@ impl MessageEncoder for UpdateInvFull { return -2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { // todo: size should be the index of the last non-empty slot diff --git a/src/out/update_inv_partial.rs b/src/out/update_inv_partial.rs index 9235276..b14d905 100644 --- a/src/out/update_inv_partial.rs +++ b/src/out/update_inv_partial.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateInvPartial { @@ -35,11 +34,6 @@ impl MessageEncoder for UpdateInvPartial { return -2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { // todo: size should be the index of the last non-empty slot diff --git a/src/out/update_inv_stop_transmit.rs b/src/out/update_inv_stop_transmit.rs index 4b66d97..63815a0 100644 --- a/src/out/update_inv_stop_transmit.rs +++ b/src/out/update_inv_stop_transmit.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateInvStopTransmit { @@ -29,11 +28,6 @@ impl MessageEncoder for UpdateInvStopTransmit { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.component); diff --git a/src/out/update_pid.rs b/src/out/update_pid.rs index d335938..f0f0e5f 100644 --- a/src/out/update_pid.rs +++ b/src/out/update_pid.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdatePid { @@ -29,11 +28,6 @@ impl MessageEncoder for UpdatePid { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; // todo: what should priority be? - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.pid); diff --git a/src/out/update_reboot_timer.rs b/src/out/update_reboot_timer.rs index 8a61c39..515bdd3 100644 --- a/src/out/update_reboot_timer.rs +++ b/src/out/update_reboot_timer.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateRebootTimer { @@ -29,11 +28,6 @@ impl MessageEncoder for UpdateRebootTimer { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; // todo: what should priority be? - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.ticks); diff --git a/src/out/update_runenergy.rs b/src/out/update_runenergy.rs index 941e609..796d143 100644 --- a/src/out/update_runenergy.rs +++ b/src/out/update_runenergy.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateRunEnergy { @@ -29,11 +28,6 @@ impl MessageEncoder for UpdateRunEnergy { return 1; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.energy / 100); diff --git a/src/out/update_runweight.rs b/src/out/update_runweight.rs index 3200a49..467af6e 100644 --- a/src/out/update_runweight.rs +++ b/src/out/update_runweight.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateRunWeight { @@ -29,11 +28,6 @@ impl MessageEncoder for UpdateRunWeight { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.kg); diff --git a/src/out/update_stat.rs b/src/out/update_stat.rs index 4889c9c..1448e71 100644 --- a/src/out/update_stat.rs +++ b/src/out/update_stat.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateStat { @@ -35,11 +34,6 @@ impl MessageEncoder for UpdateStat { return 6; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Buffered; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1(self.stat); diff --git a/src/out/update_zone_full_follows.rs b/src/out/update_zone_full_follows.rs index 30f4cfa..b467665 100644 --- a/src/out/update_zone_full_follows.rs +++ b/src/out/update_zone_full_follows.rs @@ -1,7 +1,6 @@ use crate::coord::CoordGrid; use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateZoneFullFollows { @@ -39,11 +38,6 @@ impl MessageEncoder for UpdateZoneFullFollows { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1((self.x << 3) - CoordGrid::origin(self.origin_x as u16) as i32); diff --git a/src/out/update_zone_partial_enclosed.rs b/src/out/update_zone_partial_enclosed.rs index efc767e..8e5f722 100644 --- a/src/out/update_zone_partial_enclosed.rs +++ b/src/out/update_zone_partial_enclosed.rs @@ -1,7 +1,6 @@ use crate::coord::CoordGrid; use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateZonePartialEnclosed { @@ -42,11 +41,6 @@ impl MessageEncoder for UpdateZonePartialEnclosed { return -2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1((self.x << 3) - CoordGrid::origin(self.origin_x as u16) as i32); diff --git a/src/out/update_zone_partial_follows.rs b/src/out/update_zone_partial_follows.rs index 4b81d21..c156e39 100644 --- a/src/out/update_zone_partial_follows.rs +++ b/src/out/update_zone_partial_follows.rs @@ -1,7 +1,6 @@ use crate::coord::CoordGrid; use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct UpdateZonePartialFollows { @@ -39,11 +38,6 @@ impl MessageEncoder for UpdateZonePartialFollows { return 2; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p1((self.x << 3) - CoordGrid::origin(self.origin_x as u16) as i32); diff --git a/src/out/varp_large.rs b/src/out/varp_large.rs index d7cb08b..2ef13b9 100644 --- a/src/out/varp_large.rs +++ b/src/out/varp_large.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct VarpLarge { @@ -32,11 +31,6 @@ impl MessageEncoder for VarpLarge { return 6; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.varp); diff --git a/src/out/varp_small.rs b/src/out/varp_small.rs index 8b0e4be..e0fa36a 100644 --- a/src/out/varp_small.rs +++ b/src/out/varp_small.rs @@ -1,6 +1,5 @@ use crate::message::MessageEncoder; use crate::packet::Packet; -use crate::priority::ServerProtPriority; use crate::prot::ServerInternalProt; pub struct VarpSmall { @@ -32,11 +31,6 @@ impl MessageEncoder for VarpSmall { return 3; } - #[inline] - fn priority(&self) -> ServerProtPriority { - return ServerProtPriority::Immediate; - } - #[inline] fn encode(&self, buf: &mut Packet) { buf.p2(self.varp); diff --git a/src/priority.rs b/src/priority.rs deleted file mode 100644 index 007e167..0000000 --- a/src/priority.rs +++ /dev/null @@ -1,12 +0,0 @@ -// these priorities are important for cases where the content developer wants to be aware of the -// bandwidth implications their script may run into and how it impacts the player experience -#[repr(u8)] -pub enum ServerProtPriority { - // counted as part of the buffer_full command - // alternate names: LOW, CONTENT - Buffered, - - // not counted as part of the buffer_full command - // alternate names: HIGH, ESSENTIAL, ENGINE - Immediate, -} \ No newline at end of file From b3193fb3378187458bea2675232bdda10a28410d Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 31 Mar 2025 19:51:00 -0400 Subject: [PATCH 08/14] feat: use cached packets to build byte arrays --- src/lib.rs | 15 +++++++++------ src/player.rs | 11 ++++++----- src/pool.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 src/pool.rs diff --git a/src/lib.rs b/src/lib.rs index 6552df6..6ddd9c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -108,6 +108,7 @@ use out::player_info::PlayerInfo; use std::collections::HashMap; use std::ptr::{addr_of, addr_of_mut}; use wasm_bindgen::prelude::wasm_bindgen; +use crate::pool::PacketPool; pub mod packet; pub mod renderer; @@ -124,6 +125,7 @@ mod category; mod r#in; mod out; mod pack; +mod pool; macro_rules! read { ($fn_name:ident, $js_name:literal, $struct:ty, $prot:expr) => { @@ -148,7 +150,7 @@ macro_rules! buffer { } match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { None => None, - Some(player) => player.buffer(&<$struct>::new($($arg_val),*)), + Some(player) => player.buffer(&mut *POOL, &<$struct>::new($($arg_val),*)), } } }; @@ -160,7 +162,7 @@ macro_rules! write { ($fn_name:ident, $js_name:literal, $struct:ty, ($($arg_name:ident: $arg_ty:ty),*), ($($arg_val:ident),*)) => { #[wasm_bindgen(js_name = $js_name)] pub unsafe fn $fn_name($($arg_name: $arg_ty),*) -> Vec { - Player::write(&<$struct>::new($($arg_val),*)) + Player::write(&mut *POOL, &<$struct>::new($($arg_val),*)) } }; } @@ -176,6 +178,7 @@ static mut NPC_INFO: Lazy = Lazy::new(NpcInfo::new); static mut ZONE_MAP: Lazy = Lazy::new(ZoneMap::new); static mut WORD_PACK: Lazy = Lazy::new(WordPack::new); +static mut POOL: Lazy = Lazy::new(PacketPool::new); #[wasm_bindgen(js_name = computePlayer)] pub unsafe fn compute_player( @@ -310,13 +313,13 @@ pub unsafe fn player_info(pid: i32, dx: i32, dz: i32, rebuild: bool) -> Option Option Option> { - self.write_queue.push_back(Player::write(message)); + pub fn buffer(&mut self, pool: &mut PacketPool, message: &dyn MessageEncoder) -> Option> { + self.write_queue.push_back(Player::write(pool, message)); return None; } #[inline] - pub fn write(message: &dyn MessageEncoder) -> Vec { + pub fn write(pool: &mut PacketPool, message: &dyn MessageEncoder) -> Vec { let id: i32 = message.id(); let offset: usize = match message.length() { -1 => 1 + 1, -2 => 1 + 2, _ => 1 + 0, }; - let mut buf: Packet = Packet::new(offset + message.test()); + let mut buf: &mut Packet = pool.take(offset + message.test()); buf.p1(id); match message.length() { -1 => buf.pos += 1, @@ -125,7 +126,7 @@ impl Player { -2 => buf.psize2((buf.pos - start) as u16), _ => {} }; - return buf.data; + return unsafe { buf.data.get_unchecked(0..buf.pos).to_vec() }; } #[inline] diff --git a/src/pool.rs b/src/pool.rs new file mode 100644 index 0000000..6fa1426 --- /dev/null +++ b/src/pool.rs @@ -0,0 +1,29 @@ +use crate::packet::Packet; + +pub struct PacketPool { + packet_100b: Packet, + packet_5kb: Packet, +} + +impl PacketPool { + pub fn new() -> PacketPool { + return PacketPool { + packet_100b: Packet::new(100), + packet_5kb: Packet::new(5000), + } + } + + pub fn take(&mut self, len: usize) -> &mut Packet { + return if len <= 100 { + let packet: &mut Packet = &mut self.packet_100b; + packet.pos = 0; + packet.bit_pos = 0; + packet + } else { + let packet: &mut Packet = &mut self.packet_5kb; + packet.pos = 0; + packet.bit_pos = 0; + packet + } + } +} \ No newline at end of file From 31ce292e1f3a70af7e97c40df7e95bfcfc971569 Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 31 Mar 2025 19:53:04 -0400 Subject: [PATCH 09/14] feat: remove unnecessary return --- src/lib.rs | 5 ++++- src/player.rs | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6ddd9c7..c46adcf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -150,7 +150,10 @@ macro_rules! buffer { } match &mut *PLAYERS.as_mut_ptr().add(pid as usize) { None => None, - Some(player) => player.buffer(&mut *POOL, &<$struct>::new($($arg_val),*)), + Some(player) => { + player.buffer(&mut *POOL, &<$struct>::new($($arg_val),*)); + None + }, } } }; diff --git a/src/player.rs b/src/player.rs index 22732e9..60b6c4d 100644 --- a/src/player.rs +++ b/src/player.rs @@ -99,9 +99,8 @@ impl Player { } #[inline] - pub fn buffer(&mut self, pool: &mut PacketPool, message: &dyn MessageEncoder) -> Option> { + pub fn buffer(&mut self, pool: &mut PacketPool, message: &dyn MessageEncoder) { self.write_queue.push_back(Player::write(pool, message)); - return None; } #[inline] From 476b687b01f47e679956956dc7e43c4703c1a979 Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 31 Mar 2025 19:54:47 -0400 Subject: [PATCH 10/14] feat: rename pack to wordpack --- src/lib.rs | 4 ++-- src/out/message_private.rs | 2 +- src/{pack.rs => wordpack.rs} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename src/{pack.rs => wordpack.rs} (100%) diff --git a/src/lib.rs b/src/lib.rs index c46adcf..dfb6859 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ use crate::out::update_zone_partial_enclosed::UpdateZonePartialEnclosed; use crate::out::update_zone_partial_follows::UpdateZonePartialFollows; use crate::out::varp_large::VarpLarge; use crate::out::varp_small::VarpSmall; -use crate::pack::WordPack; +use crate::wordpack::WordPack; use crate::packet::Packet; use crate::player::{Chat, ExactMove, Player}; use crate::prot::{ClientInternalProt, ClientProt, ServerInternalProt}; @@ -124,7 +124,7 @@ mod visibility; mod category; mod r#in; mod out; -mod pack; +mod wordpack; mod pool; macro_rules! read { diff --git a/src/out/message_private.rs b/src/out/message_private.rs index b5d690d..25cf389 100644 --- a/src/out/message_private.rs +++ b/src/out/message_private.rs @@ -1,5 +1,5 @@ use crate::message::MessageEncoder; -use crate::pack::WordPack; +use crate::wordpack::WordPack; use crate::packet::Packet; use crate::prot::ServerInternalProt; diff --git a/src/pack.rs b/src/wordpack.rs similarity index 100% rename from src/pack.rs rename to src/wordpack.rs From f12a55236ff7c88b2b3c130401bbf2d307ca3b74 Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 31 Mar 2025 20:28:37 -0400 Subject: [PATCH 11/14] fix: wordpack --- src/lib.rs | 2 +- src/wordpack.rs | 69 ++++++++++++++++++++++------------------------- tests/wordpack.rs | 24 +++++++++++++++++ 3 files changed, 57 insertions(+), 38 deletions(-) create mode 100644 tests/wordpack.rs diff --git a/src/lib.rs b/src/lib.rs index dfb6859..9e41b40 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,6 +113,7 @@ use crate::pool::PacketPool; pub mod packet; pub mod renderer; pub mod build; +pub mod wordpack; mod coord; mod player; @@ -124,7 +125,6 @@ mod visibility; mod category; mod r#in; mod out; -mod wordpack; mod pool; macro_rules! read { diff --git a/src/wordpack.rs b/src/wordpack.rs index 9a66882..cdf7a3b 100644 --- a/src/wordpack.rs +++ b/src/wordpack.rs @@ -1,7 +1,8 @@ use crate::packet::Packet; pub struct WordPack { - buf: Packet, + pack: Packet, + unpack: Vec, } impl WordPack { @@ -17,18 +18,19 @@ impl WordPack { #[inline] pub fn new() -> WordPack { return WordPack { - buf: Packet::new(100), + pack: Packet::new(100), + unpack: Vec::with_capacity(100), }; } #[inline] - pub unsafe fn unpack(&self, mut packet: Packet, length: usize) -> String { - let mut char_buffer: Vec = Vec::with_capacity(80); - let mut pos: usize = 0; + pub unsafe fn unpack(&mut self, mut packet: Packet, length: usize) -> String { + self.unpack.clear(); + let mut carry: i32 = -1; for _ in 0..length { - if pos >= 80 { + if self.unpack.len() >= 80 { break; } @@ -36,15 +38,10 @@ impl WordPack { let mut nibble: u8 = (data >> 4) & 0xf; if carry != -1 { - let index: i32 = ((carry << 4) + nibble as i32) - 195; - if index >= 0 && index < WordPack::CHAR_LOOKUP.len() as i32 { - *char_buffer.as_mut_ptr().add(pos) = *WordPack::CHAR_LOOKUP.as_ptr().add(index as usize); - pos += 1; - } + self.unpack.push(*WordPack::CHAR_LOOKUP.as_ptr().add((((carry << 4) + nibble as i32) - 195) as usize)); carry = -1; } else if nibble < 13 { - *char_buffer.as_mut_ptr().add(pos) = *WordPack::CHAR_LOOKUP.as_ptr().add(nibble as usize); - pos += 1; + self.unpack.push(*WordPack::CHAR_LOOKUP.as_ptr().add(nibble as usize)); } else { carry = nibble as i32; } @@ -52,34 +49,35 @@ impl WordPack { nibble = data & 0xf; if carry != -1 { - let index: i32 = ((carry << 4) + nibble as i32) - 195; - if index >= 0 && index < WordPack::CHAR_LOOKUP.len() as i32 { - *char_buffer.as_mut_ptr().add(pos) = *WordPack::CHAR_LOOKUP.as_ptr().add(index as usize); - pos += 1; - } + self.unpack.push(*WordPack::CHAR_LOOKUP.as_ptr().add((((carry << 4) + nibble as i32) - 195) as usize)); carry = -1; } else if nibble < 13 { - *char_buffer.as_mut_ptr().add(pos) = *WordPack::CHAR_LOOKUP.as_ptr().add(nibble as usize); - pos += 1; + self.unpack.push(*WordPack::CHAR_LOOKUP.as_ptr().add(nibble as usize)); } else { carry = nibble as i32; } } - WordPack::sentence_case(&char_buffer.get_unchecked(..pos).iter().collect::()) + WordPack::sentence_case(&mut self.unpack); + + return self.unpack.iter().collect(); } #[inline] - pub unsafe fn pack(&mut self, mut input: String) -> Vec { - self.buf.pos = 0; + pub unsafe fn pack(&mut self, input: String) -> Vec { + self.pack.pos = 0; - if input.len() > 80 { - input.truncate(80); - } - input = input.to_lowercase(); let mut carry: i32 = -1; + let mut count: i32 = 0; for c in input.chars() { + if count >= 80 { + break; + } + + let c: char = c.to_ascii_lowercase(); + count += 1; + let mut index = 0; for (j, &ch) in WordPack::CHAR_LOOKUP.iter().enumerate() { if ch == c { @@ -96,28 +94,27 @@ impl WordPack { if index < 13 { carry = index; } else { - self.buf.p1(index); + self.pack.p1(index); } } else if index < 13 { - self.buf.p1((carry << 4) + index); + self.pack.p1((carry << 4) + index); carry = -1; } else { - self.buf.p1((carry << 4) + (index >> 4)); + self.pack.p1((carry << 4) + (index >> 4)); carry = index & 0xf; } } if carry != -1 { - self.buf.p1(carry << 4); + self.pack.p1(carry << 4); } - return self.buf.data.get_unchecked(0..self.buf.pos).to_vec(); + return self.pack.data.get_unchecked(0..self.pack.pos).to_vec(); } #[inline] - pub fn sentence_case(input: &str) -> String { - let mut chars: Vec = input.to_lowercase().chars().collect(); - let mut punctuation: bool = true; + pub fn sentence_case(chars: &mut [char]) { + let mut punctuation = true; for c in chars.iter_mut() { if punctuation && c.is_ascii_lowercase() { @@ -129,7 +126,5 @@ impl WordPack { punctuation = true; } } - - return chars.iter().collect(); } } \ No newline at end of file diff --git a/tests/wordpack.rs b/tests/wordpack.rs new file mode 100644 index 0000000..ded4c63 --- /dev/null +++ b/tests/wordpack.rs @@ -0,0 +1,24 @@ +use rsbuf::packet::Packet; +use rsbuf::wordpack::WordPack; + +#[test] +fn test_unpack_test() { + let packet: Packet = Packet::from(vec![33, 130]); + unsafe { assert_eq!("Test", WordPack::new().unpack(packet, 2)) }; +} + +#[test] +fn test_unpack_zezima() { + let packet: Packet = Packet::from(vec![221, 29, 213, 208, 48]); + unsafe { assert_eq!("Zezima ", WordPack::new().unpack(packet, 5)) }; +} + +#[test] +fn test_pack_test() { + unsafe { assert_eq!(WordPack::new().pack("Test".to_string()), vec![33, 130]) }; +} + +#[test] +fn test_pack_zezima() { + unsafe { assert_eq!(WordPack::new().pack("Zezima".to_string()), vec![221, 29, 213, 208, 48]) }; +} From 12d093d7a7109872917a74d265a8305bd5a66475 Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 31 Mar 2025 23:40:06 -0400 Subject: [PATCH 12/14] feat: export isBufferFull --- src/build.rs | 16 ++++++------- src/in/anticheat.rs | 30 ------------------------- src/in/chat_setmode.rs | 2 -- src/in/client_cheat.rs | 2 -- src/in/close_modal.rs | 2 -- src/in/event.rs | 4 ---- src/in/friend.rs | 4 ---- src/in/idle_timer.rs | 2 -- src/in/if_button.rs | 2 -- src/in/if_playerdesign.rs | 2 -- src/in/ignore.rs | 4 ---- src/in/inv_button.rs | 4 ---- src/in/message_private.rs | 2 -- src/in/message_public.rs | 2 -- src/in/move_click.rs | 2 -- src/in/no_timeout.rs | 2 -- src/in/opheld.rs | 6 ----- src/in/oploc.rs | 6 ----- src/in/opnpc.rs | 6 ----- src/in/opobj.rs | 6 ----- src/in/opplayer.rs | 6 ----- src/in/rebuild_getmaps.rs | 2 -- src/in/reportabuse.rs | 2 -- src/in/resume_countdialog.rs | 2 -- src/in/resume_pausebutton.rs | 2 -- src/in/tutorial_clickside.rs | 2 -- src/lib.rs | 28 +++++++++++++++++++++-- src/out/cam_lookat.rs | 2 +- src/out/cam_moveto.rs | 2 +- src/out/cam_reset.rs | 2 +- src/out/cam_shake.rs | 2 +- src/out/chat_filter_settings.rs | 2 +- src/out/count_dialog.rs | 2 +- src/out/data_land.rs | 4 ++-- src/out/data_loc.rs | 4 ++-- src/out/enable_tracking.rs | 2 +- src/out/finish_tracking.rs | 2 +- src/out/hint_arrow.rs | 2 +- src/out/if_close.rs | 2 +- src/out/if_openchat.rs | 2 +- src/out/if_openmain.rs | 2 +- src/out/if_openmainside.rs | 2 +- src/out/if_openside.rs | 2 +- src/out/if_setanim.rs | 2 +- src/out/if_setcolour.rs | 2 +- src/out/if_sethide.rs | 2 +- src/out/if_setmodel.rs | 2 +- src/out/if_setnpchead.rs | 2 +- src/out/if_setobject.rs | 2 +- src/out/if_setplayerhead.rs | 2 +- src/out/if_setposition.rs | 2 +- src/out/if_setrecol.rs | 2 +- src/out/if_settab.rs | 2 +- src/out/if_settabactive.rs | 2 +- src/out/if_settext.rs | 2 +- src/out/last_login_info.rs | 2 +- src/out/loc_addchange.rs | 2 +- src/out/loc_anim.rs | 2 +- src/out/loc_del.rs | 2 +- src/out/loc_merge.rs | 2 +- src/out/logout.rs | 2 +- src/out/map_anim.rs | 2 +- src/out/map_projanim.rs | 2 +- src/out/message_game.rs | 2 +- src/out/message_private.rs | 4 ++-- src/out/midi_jingle.rs | 2 +- src/out/midi_song.rs | 2 +- src/out/obj_add.rs | 2 +- src/out/obj_count.rs | 2 +- src/out/obj_del.rs | 2 +- src/out/obj_reveal.rs | 2 +- src/out/rebuild_normal.rs | 2 +- src/out/reset_anims.rs | 2 +- src/out/reset_clientvarcache.rs | 2 +- src/out/set_multiway.rs | 2 +- src/out/synth_sound.rs | 2 +- src/out/tut_flash.rs | 2 +- src/out/tut_open.rs | 2 +- src/out/unset_map_flag.rs | 2 +- src/out/update_friendlist.rs | 2 +- src/out/update_ignorelist.rs | 2 +- src/out/update_inv_full.rs | 2 +- src/out/update_inv_partial.rs | 2 +- src/out/update_inv_stop_transmit.rs | 2 +- src/out/update_pid.rs | 2 +- src/out/update_reboot_timer.rs | 2 +- src/out/update_runenergy.rs | 2 +- src/out/update_runweight.rs | 2 +- src/out/update_stat.rs | 2 +- src/out/update_zone_full_follows.rs | 2 +- src/out/update_zone_partial_enclosed.rs | 2 +- src/out/update_zone_partial_follows.rs | 2 +- src/out/varp_large.rs | 2 +- src/out/varp_small.rs | 2 +- src/player.rs | 2 +- 95 files changed, 105 insertions(+), 187 deletions(-) diff --git a/src/build.rs b/src/build.rs index 4725be8..d2f4c38 100644 --- a/src/build.rs +++ b/src/build.rs @@ -305,10 +305,10 @@ impl BuildArea { y: u8, z: u16 ) -> bool { - if let Some(other) = unsafe { &*players.as_ptr().add(player as usize) } { - return !(self.players.contains(player) || !CoordGrid::within_distance_sw(&other.coord, &CoordGrid::from(x, y, z), self.view_distance) || other.pid == -1 || other.pid == pid || other.coord.y() != y); - } - return false; + return match unsafe { &*players.as_ptr().add(player as usize) } { + None => false, + Some(other) => !(self.players.contains(player) || !CoordGrid::within_distance_sw(&other.coord, &CoordGrid::from(x, y, z), self.view_distance) || other.pid == -1 || other.pid == pid || other.coord.y() != y), + }; } #[inline] @@ -320,9 +320,9 @@ impl BuildArea { y: u8, z: u16 ) -> bool { - if let Some(other) = unsafe { &*npcs.as_ptr().add(npc as usize) } { - return !(self.npcs.contains(npc) || !CoordGrid::within_distance_sw(&other.coord, &CoordGrid::from(x, y, z), BuildArea::PREFERRED_VIEW_DISTANCE) || other.nid == -1 || other.coord.y() != y || !other.active); - } - return false; + return match unsafe { &*npcs.as_ptr().add(npc as usize) } { + None => false, + Some(other) => !(self.npcs.contains(npc) || !CoordGrid::within_distance_sw(&other.coord, &CoordGrid::from(x, y, z), BuildArea::PREFERRED_VIEW_DISTANCE) || other.nid == -1 || other.coord.y() != y || !other.active), + }; } } \ No newline at end of file diff --git a/src/in/anticheat.rs b/src/in/anticheat.rs index 7cb9ed3..2a7a1bb 100644 --- a/src/in/anticheat.rs +++ b/src/in/anticheat.rs @@ -6,9 +6,7 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen] pub struct AnticheatOp1 {} -#[wasm_bindgen] impl AnticheatOp1 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatOp1 { return AnticheatOp1 {}; @@ -32,9 +30,7 @@ impl MessageDecoder for AnticheatOp1 { #[wasm_bindgen] pub struct AnticheatOp2 {} -#[wasm_bindgen] impl AnticheatOp2 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatOp2 { return AnticheatOp2 {}; @@ -58,9 +54,7 @@ impl MessageDecoder for AnticheatOp2 { #[wasm_bindgen] pub struct AnticheatOp3 {} -#[wasm_bindgen] impl AnticheatOp3 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatOp3 { return AnticheatOp3 {}; @@ -84,9 +78,7 @@ impl MessageDecoder for AnticheatOp3 { #[wasm_bindgen] pub struct AnticheatOp4 {} -#[wasm_bindgen] impl AnticheatOp4 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatOp4 { return AnticheatOp4 {}; @@ -110,9 +102,7 @@ impl MessageDecoder for AnticheatOp4 { #[wasm_bindgen] pub struct AnticheatOp5 {} -#[wasm_bindgen] impl AnticheatOp5 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatOp5 { return AnticheatOp5 {}; @@ -136,9 +126,7 @@ impl MessageDecoder for AnticheatOp5 { #[wasm_bindgen] pub struct AnticheatOp6 {} -#[wasm_bindgen] impl AnticheatOp6 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatOp6 { return AnticheatOp6 {}; @@ -162,9 +150,7 @@ impl MessageDecoder for AnticheatOp6 { #[wasm_bindgen] pub struct AnticheatOp7 {} -#[wasm_bindgen] impl AnticheatOp7 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatOp7 { return AnticheatOp7 {}; @@ -188,9 +174,7 @@ impl MessageDecoder for AnticheatOp7 { #[wasm_bindgen] pub struct AnticheatOp8 {} -#[wasm_bindgen] impl AnticheatOp8 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatOp8 { return AnticheatOp8 {}; @@ -214,9 +198,7 @@ impl MessageDecoder for AnticheatOp8 { #[wasm_bindgen] pub struct AnticheatOp9 {} -#[wasm_bindgen] impl AnticheatOp9 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatOp9 { return AnticheatOp9 {}; @@ -240,9 +222,7 @@ impl MessageDecoder for AnticheatOp9 { #[wasm_bindgen] pub struct AnticheatCycle1 {} -#[wasm_bindgen] impl AnticheatCycle1 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatCycle1 { return AnticheatCycle1 {}; @@ -266,9 +246,7 @@ impl MessageDecoder for AnticheatCycle1 { #[wasm_bindgen] pub struct AnticheatCycle2 {} -#[wasm_bindgen] impl AnticheatCycle2 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatCycle2 { return AnticheatCycle2 {}; @@ -292,9 +270,7 @@ impl MessageDecoder for AnticheatCycle2 { #[wasm_bindgen] pub struct AnticheatCycle3 {} -#[wasm_bindgen] impl AnticheatCycle3 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatCycle3 { return AnticheatCycle3 {}; @@ -318,9 +294,7 @@ impl MessageDecoder for AnticheatCycle3 { #[wasm_bindgen] pub struct AnticheatCycle4 {} -#[wasm_bindgen] impl AnticheatCycle4 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatCycle4 { return AnticheatCycle4 {}; @@ -344,9 +318,7 @@ impl MessageDecoder for AnticheatCycle4 { #[wasm_bindgen] pub struct AnticheatCycle5 {} -#[wasm_bindgen] impl AnticheatCycle5 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatCycle5 { return AnticheatCycle5 {}; @@ -370,9 +342,7 @@ impl MessageDecoder for AnticheatCycle5 { #[wasm_bindgen] pub struct AnticheatCycle6 {} -#[wasm_bindgen] impl AnticheatCycle6 { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> AnticheatCycle6 { return AnticheatCycle6 {}; diff --git a/src/in/chat_setmode.rs b/src/in/chat_setmode.rs index faf5771..027a6dd 100644 --- a/src/in/chat_setmode.rs +++ b/src/in/chat_setmode.rs @@ -13,9 +13,7 @@ pub struct ChatSetMode { pub trade: u8, } -#[wasm_bindgen] impl ChatSetMode { - #[wasm_bindgen(constructor)] #[inline] pub fn new( public: u8, diff --git a/src/in/client_cheat.rs b/src/in/client_cheat.rs index 8a380ab..974f2ee 100644 --- a/src/in/client_cheat.rs +++ b/src/in/client_cheat.rs @@ -9,9 +9,7 @@ pub struct ClientCheat { pub input: String, } -#[wasm_bindgen] impl ClientCheat { - #[wasm_bindgen(constructor)] #[inline] pub fn new(input: String) -> ClientCheat { return ClientCheat { diff --git a/src/in/close_modal.rs b/src/in/close_modal.rs index a1cf2d8..8c0bd58 100644 --- a/src/in/close_modal.rs +++ b/src/in/close_modal.rs @@ -6,9 +6,7 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen] pub struct CloseModal {} -#[wasm_bindgen] impl CloseModal { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> CloseModal { return CloseModal {} diff --git a/src/in/event.rs b/src/in/event.rs index 41cb196..a6d2837 100644 --- a/src/in/event.rs +++ b/src/in/event.rs @@ -9,9 +9,7 @@ pub struct EventTracking { pub bytes: Vec, } -#[wasm_bindgen] impl EventTracking { - #[wasm_bindgen(constructor)] #[inline] pub fn new(bytes: Vec) -> EventTracking { return EventTracking { @@ -46,9 +44,7 @@ pub struct EventCameraPosition { pub zoom: i32, } -#[wasm_bindgen] impl EventCameraPosition { - #[wasm_bindgen(constructor)] #[inline] pub fn new( pitch: i32, diff --git a/src/in/friend.rs b/src/in/friend.rs index 7bb76cb..7143182 100644 --- a/src/in/friend.rs +++ b/src/in/friend.rs @@ -9,9 +9,7 @@ pub struct FriendListAdd { pub username: i64, } -#[wasm_bindgen] impl FriendListAdd { - #[wasm_bindgen(constructor)] #[inline] pub fn new(username: i64) -> FriendListAdd { return FriendListAdd { @@ -40,9 +38,7 @@ pub struct FriendListDel { pub username: i64, } -#[wasm_bindgen] impl FriendListDel { - #[wasm_bindgen(constructor)] #[inline] pub fn new(username: i64) -> FriendListDel { return FriendListDel { diff --git a/src/in/idle_timer.rs b/src/in/idle_timer.rs index 8346f35..94fd29c 100644 --- a/src/in/idle_timer.rs +++ b/src/in/idle_timer.rs @@ -6,9 +6,7 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen] pub struct IdleTimer {} -#[wasm_bindgen] impl IdleTimer { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> IdleTimer { return IdleTimer {} diff --git a/src/in/if_button.rs b/src/in/if_button.rs index 39f09b6..810fe74 100644 --- a/src/in/if_button.rs +++ b/src/in/if_button.rs @@ -9,9 +9,7 @@ pub struct IfButton { pub component: u16, } -#[wasm_bindgen] impl IfButton { - #[wasm_bindgen(constructor)] #[inline] pub fn new(component: u16) -> IfButton { return IfButton { diff --git a/src/in/if_playerdesign.rs b/src/in/if_playerdesign.rs index e2388b2..a3f4149 100644 --- a/src/in/if_playerdesign.rs +++ b/src/in/if_playerdesign.rs @@ -13,9 +13,7 @@ pub struct IfPlayerDesign { pub color: Vec, } -#[wasm_bindgen] impl IfPlayerDesign { - #[wasm_bindgen(constructor)] #[inline] pub fn new( gender: u8, diff --git a/src/in/ignore.rs b/src/in/ignore.rs index 629bf1d..17c40c2 100644 --- a/src/in/ignore.rs +++ b/src/in/ignore.rs @@ -9,9 +9,7 @@ pub struct IgnoreListAdd { pub username: i64, } -#[wasm_bindgen] impl IgnoreListAdd { - #[wasm_bindgen(constructor)] #[inline] pub fn new(username: i64) -> IgnoreListAdd { return IgnoreListAdd { @@ -40,9 +38,7 @@ pub struct IgnoreListDel { pub username: i64, } -#[wasm_bindgen] impl IgnoreListDel { - #[wasm_bindgen(constructor)] #[inline] pub fn new(username: i64) -> IgnoreListDel { return IgnoreListDel { diff --git a/src/in/inv_button.rs b/src/in/inv_button.rs index 7c30d96..d560d15 100644 --- a/src/in/inv_button.rs +++ b/src/in/inv_button.rs @@ -15,9 +15,7 @@ pub struct InvButton { pub component: u16, } -#[wasm_bindgen] impl InvButton { - #[wasm_bindgen(constructor)] #[inline] pub fn new( op: u8, @@ -71,9 +69,7 @@ pub struct InvButtonD { pub target: u16, } -#[wasm_bindgen] impl InvButtonD { - #[wasm_bindgen(constructor)] #[inline] pub fn new( component: u16, diff --git a/src/in/message_private.rs b/src/in/message_private.rs index 1db77fc..1e83f66 100644 --- a/src/in/message_private.rs +++ b/src/in/message_private.rs @@ -11,9 +11,7 @@ pub struct MessagePrivate { pub input: Vec, } -#[wasm_bindgen] impl MessagePrivate { - #[wasm_bindgen(constructor)] #[inline] pub fn new( username: i64, diff --git a/src/in/message_public.rs b/src/in/message_public.rs index 8e1c719..8abe363 100644 --- a/src/in/message_public.rs +++ b/src/in/message_public.rs @@ -13,9 +13,7 @@ pub struct MessagePublic { pub input: Vec, } -#[wasm_bindgen] impl MessagePublic { - #[wasm_bindgen(constructor)] #[inline] pub fn new( color: u8, diff --git a/src/in/move_click.rs b/src/in/move_click.rs index f81bac7..ecab521 100644 --- a/src/in/move_click.rs +++ b/src/in/move_click.rs @@ -14,9 +14,7 @@ pub struct MoveClick { pub path: Vec, } -#[wasm_bindgen] impl MoveClick { - #[wasm_bindgen(constructor)] #[inline] pub fn new( ctrl: bool, diff --git a/src/in/no_timeout.rs b/src/in/no_timeout.rs index 57680e3..452a351 100644 --- a/src/in/no_timeout.rs +++ b/src/in/no_timeout.rs @@ -6,9 +6,7 @@ use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen] pub struct NoTimeout {} -#[wasm_bindgen] impl NoTimeout { - #[wasm_bindgen(constructor)] #[inline] pub fn new() -> NoTimeout { return NoTimeout {}; diff --git a/src/in/opheld.rs b/src/in/opheld.rs index 2a415dd..44829dd 100644 --- a/src/in/opheld.rs +++ b/src/in/opheld.rs @@ -15,9 +15,7 @@ pub struct OpHeld { pub component: u16, } -#[wasm_bindgen] impl OpHeld { - #[wasm_bindgen(constructor)] #[inline] pub fn new( op: u8, @@ -73,9 +71,7 @@ pub struct OpHeldT { pub spell: u16, } -#[wasm_bindgen] impl OpHeldT { - #[wasm_bindgen(constructor)] #[inline] pub fn new( obj: u16, @@ -127,9 +123,7 @@ pub struct OpHeldU { pub use_component: u16, } -#[wasm_bindgen] impl OpHeldU { - #[wasm_bindgen(constructor)] #[inline] pub fn new( obj: u16, diff --git a/src/in/oploc.rs b/src/in/oploc.rs index 4e67143..d055c45 100644 --- a/src/in/oploc.rs +++ b/src/in/oploc.rs @@ -15,9 +15,7 @@ pub struct OpLoc { pub loc: u16, } -#[wasm_bindgen] impl OpLoc { - #[wasm_bindgen(constructor)] #[inline] pub fn new( op: u8, @@ -73,9 +71,7 @@ pub struct OpLocT { pub spell: u16, } -#[wasm_bindgen] impl OpLocT { - #[wasm_bindgen(constructor)] #[inline] pub fn new( x: u16, @@ -127,9 +123,7 @@ pub struct OpLocU { pub use_component: u16, } -#[wasm_bindgen] impl OpLocU { - #[wasm_bindgen(constructor)] #[inline] pub fn new( x: u16, diff --git a/src/in/opnpc.rs b/src/in/opnpc.rs index bb21032..7b83c8e 100644 --- a/src/in/opnpc.rs +++ b/src/in/opnpc.rs @@ -11,9 +11,7 @@ pub struct OpNpc { pub nid: u16, } -#[wasm_bindgen] impl OpNpc { - #[wasm_bindgen(constructor)] #[inline] pub fn new( op: u8, @@ -59,9 +57,7 @@ pub struct OpNpcT { pub spell: u16, } -#[wasm_bindgen] impl OpNpcT { - #[wasm_bindgen(constructor)] #[inline] pub fn new( nid: u16, @@ -103,9 +99,7 @@ pub struct OpNpcU { pub use_component: u16, } -#[wasm_bindgen] impl OpNpcU { - #[wasm_bindgen(constructor)] #[inline] pub fn new( nid: u16, diff --git a/src/in/opobj.rs b/src/in/opobj.rs index c4445e8..1a8de8f 100644 --- a/src/in/opobj.rs +++ b/src/in/opobj.rs @@ -15,9 +15,7 @@ pub struct OpObj { pub obj: u16, } -#[wasm_bindgen] impl OpObj { - #[wasm_bindgen(constructor)] #[inline] pub fn new( op: u8, @@ -73,9 +71,7 @@ pub struct OpObjT { pub spell: u16, } -#[wasm_bindgen] impl OpObjT { - #[wasm_bindgen(constructor)] #[inline] pub fn new( x: u16, @@ -127,9 +123,7 @@ pub struct OpObjU { pub use_component: u16, } -#[wasm_bindgen] impl OpObjU { - #[wasm_bindgen(constructor)] #[inline] pub fn new( x: u16, diff --git a/src/in/opplayer.rs b/src/in/opplayer.rs index aaa96d3..d226271 100644 --- a/src/in/opplayer.rs +++ b/src/in/opplayer.rs @@ -11,9 +11,7 @@ pub struct OpPlayer { pub pid: u16, } -#[wasm_bindgen] impl OpPlayer { - #[wasm_bindgen(constructor)] #[inline] pub fn new( op: u8, @@ -58,9 +56,7 @@ pub struct OpPlayerT { pub spell: u16, } -#[wasm_bindgen] impl OpPlayerT { - #[wasm_bindgen(constructor)] #[inline] pub fn new( pid: u16, @@ -102,9 +98,7 @@ pub struct OpPlayerU { pub use_component: u16, } -#[wasm_bindgen] impl OpPlayerU { - #[wasm_bindgen(constructor)] #[inline] pub fn new( pid: u16, diff --git a/src/in/rebuild_getmaps.rs b/src/in/rebuild_getmaps.rs index 2bc498a..6fe829c 100644 --- a/src/in/rebuild_getmaps.rs +++ b/src/in/rebuild_getmaps.rs @@ -9,9 +9,7 @@ pub struct RebuildGetMaps { pub maps: Vec, } -#[wasm_bindgen] impl RebuildGetMaps { - #[wasm_bindgen(constructor)] #[inline] pub fn new(maps: Vec) -> RebuildGetMaps { return RebuildGetMaps { diff --git a/src/in/reportabuse.rs b/src/in/reportabuse.rs index b545247..6223bc2 100644 --- a/src/in/reportabuse.rs +++ b/src/in/reportabuse.rs @@ -13,9 +13,7 @@ pub struct ReportAbuse { pub mute: bool, } -#[wasm_bindgen] impl ReportAbuse { - #[wasm_bindgen(constructor)] #[inline] pub fn new( offender: i64, diff --git a/src/in/resume_countdialog.rs b/src/in/resume_countdialog.rs index b293fb1..300d6d0 100644 --- a/src/in/resume_countdialog.rs +++ b/src/in/resume_countdialog.rs @@ -9,9 +9,7 @@ pub struct ResumePCountDialog { pub input: i32, } -#[wasm_bindgen] impl ResumePCountDialog { - #[wasm_bindgen(constructor)] #[inline] pub fn new(input: i32) -> ResumePCountDialog { return ResumePCountDialog { diff --git a/src/in/resume_pausebutton.rs b/src/in/resume_pausebutton.rs index 6348810..c9b232c 100644 --- a/src/in/resume_pausebutton.rs +++ b/src/in/resume_pausebutton.rs @@ -9,9 +9,7 @@ pub struct ResumePauseButton { pub component: u16, } -#[wasm_bindgen] impl ResumePauseButton { - #[wasm_bindgen(constructor)] #[inline] pub fn new(component: u16) -> ResumePauseButton { return ResumePauseButton { diff --git a/src/in/tutorial_clickside.rs b/src/in/tutorial_clickside.rs index d471dfe..3583a26 100644 --- a/src/in/tutorial_clickside.rs +++ b/src/in/tutorial_clickside.rs @@ -9,9 +9,7 @@ pub struct TutorialClickSide { pub tab: u8, } -#[wasm_bindgen] impl TutorialClickSide { - #[wasm_bindgen(constructor)] #[inline] pub fn new(tab: u8) -> TutorialClickSide { return TutorialClickSide { diff --git a/src/lib.rs b/src/lib.rs index 9e41b40..a353bc1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,9 +72,9 @@ use crate::out::update_zone_partial_enclosed::UpdateZonePartialEnclosed; use crate::out::update_zone_partial_follows::UpdateZonePartialFollows; use crate::out::varp_large::VarpLarge; use crate::out::varp_small::VarpSmall; -use crate::wordpack::WordPack; use crate::packet::Packet; use crate::player::{Chat, ExactMove, Player}; +use crate::pool::PacketPool; use crate::prot::{ClientInternalProt, ClientProt, ServerInternalProt}; use crate::r#in::anticheat::{AnticheatCycle1, AnticheatCycle2, AnticheatCycle3, AnticheatCycle4, AnticheatCycle5, AnticheatCycle6, AnticheatOp1, AnticheatOp2, AnticheatOp3, AnticheatOp4, AnticheatOp5, AnticheatOp6, AnticheatOp7, AnticheatOp8, AnticheatOp9}; use crate::r#in::chat_setmode::ChatSetMode; @@ -103,12 +103,12 @@ use crate::r#in::resume_pausebutton::ResumePauseButton; use crate::r#in::tutorial_clickside::TutorialClickSide; use crate::renderer::{NpcRenderer, PlayerRenderer}; use crate::visibility::Visibility; +use crate::wordpack::WordPack; use once_cell::sync::Lazy; use out::player_info::PlayerInfo; use std::collections::HashMap; use std::ptr::{addr_of, addr_of_mut}; use wasm_bindgen::prelude::wasm_bindgen; -use crate::pool::PacketPool; pub mod packet; pub mod renderer; @@ -788,6 +788,30 @@ pub unsafe fn next_buffered_read(id: i32) -> i16 { } } +#[wasm_bindgen(js_name = isBufferFull)] +pub unsafe fn is_buffer_full(pid: i32) -> bool { + if pid == -1 { + return false; + } + return match &*PLAYERS.as_ptr().add(pid as usize) { + None => false, + Some(player) => player + .write_queue + .iter() + .map(|packet| packet.len()) + .scan(0, |acc, len| { + *acc += len; + return if *acc >= 5000 { + None + } else { + Some(*acc) + } + }) + .last() + .unwrap_or(0) >= 5000 + }; +} + #[wasm_bindgen(js_name = unpackWords)] pub unsafe fn unpack_words(bytes: Vec, length: usize) -> String { return WORD_PACK.unpack(Packet::from(bytes), length); diff --git a/src/out/cam_lookat.rs b/src/out/cam_lookat.rs index 16d9b82..39711a1 100644 --- a/src/out/cam_lookat.rs +++ b/src/out/cam_lookat.rs @@ -12,7 +12,7 @@ pub struct CamLookAt { impl CamLookAt { #[inline] - pub fn new( + pub const fn new( x: i32, z: i32, height: i32, diff --git a/src/out/cam_moveto.rs b/src/out/cam_moveto.rs index 686b7a0..ebb5951 100644 --- a/src/out/cam_moveto.rs +++ b/src/out/cam_moveto.rs @@ -12,7 +12,7 @@ pub struct CamMoveTo { impl CamMoveTo { #[inline] - pub fn new( + pub const fn new( x: i32, z: i32, height: i32, diff --git a/src/out/cam_reset.rs b/src/out/cam_reset.rs index d1a23b3..23124dd 100644 --- a/src/out/cam_reset.rs +++ b/src/out/cam_reset.rs @@ -6,7 +6,7 @@ pub struct CamReset {} impl CamReset { #[inline] - pub fn new() -> CamReset { + pub const fn new() -> CamReset { return CamReset {} } } diff --git a/src/out/cam_shake.rs b/src/out/cam_shake.rs index 69ca249..6542715 100644 --- a/src/out/cam_shake.rs +++ b/src/out/cam_shake.rs @@ -11,7 +11,7 @@ pub struct CamShake { impl CamShake { #[inline] - pub fn new( + pub const fn new( shake: i32, jitter: i32, amplitude: i32, diff --git a/src/out/chat_filter_settings.rs b/src/out/chat_filter_settings.rs index 6901b42..001fa7b 100644 --- a/src/out/chat_filter_settings.rs +++ b/src/out/chat_filter_settings.rs @@ -10,7 +10,7 @@ pub struct ChatFilterSettings { impl ChatFilterSettings { #[inline] - pub fn new( + pub const fn new( public: i32, private: i32, trade: i32, diff --git a/src/out/count_dialog.rs b/src/out/count_dialog.rs index 70dd93a..38e930a 100644 --- a/src/out/count_dialog.rs +++ b/src/out/count_dialog.rs @@ -6,7 +6,7 @@ pub struct PCountDialog {} impl PCountDialog { #[inline] - pub fn new() -> PCountDialog { + pub const fn new() -> PCountDialog { return PCountDialog {} } } diff --git a/src/out/data_land.rs b/src/out/data_land.rs index c708419..7845861 100644 --- a/src/out/data_land.rs +++ b/src/out/data_land.rs @@ -12,7 +12,7 @@ pub struct DataLand { impl DataLand { #[inline] - pub fn new( + pub const fn new( x: i32, z: i32, offset: i32, @@ -64,7 +64,7 @@ pub struct DataLandDone { impl DataLandDone { #[inline] - pub fn new( + pub const fn new( x: i32, z: i32, ) -> DataLandDone { diff --git a/src/out/data_loc.rs b/src/out/data_loc.rs index 07ab8ac..5625bfa 100644 --- a/src/out/data_loc.rs +++ b/src/out/data_loc.rs @@ -12,7 +12,7 @@ pub struct DataLoc { impl DataLoc { #[inline] - pub fn new( + pub const fn new( x: i32, z: i32, offset: i32, @@ -64,7 +64,7 @@ pub struct DataLocDone { impl DataLocDone { #[inline] - pub fn new( + pub const fn new( x: i32, z: i32, ) -> DataLocDone { diff --git a/src/out/enable_tracking.rs b/src/out/enable_tracking.rs index e11fe95..d968026 100644 --- a/src/out/enable_tracking.rs +++ b/src/out/enable_tracking.rs @@ -6,7 +6,7 @@ pub struct EnableTracking {} impl EnableTracking { #[inline] - pub fn new() -> EnableTracking { + pub const fn new() -> EnableTracking { return EnableTracking {} } } diff --git a/src/out/finish_tracking.rs b/src/out/finish_tracking.rs index 441975f..e2e4584 100644 --- a/src/out/finish_tracking.rs +++ b/src/out/finish_tracking.rs @@ -6,7 +6,7 @@ pub struct FinishTracking {} impl FinishTracking { #[inline] - pub fn new() -> FinishTracking { + pub const fn new() -> FinishTracking { return FinishTracking {} } } diff --git a/src/out/hint_arrow.rs b/src/out/hint_arrow.rs index a90b9e4..1ef679f 100644 --- a/src/out/hint_arrow.rs +++ b/src/out/hint_arrow.rs @@ -13,7 +13,7 @@ pub struct HintArrow { impl HintArrow { #[inline] - pub fn new( + pub const fn new( arrow: i32, nid: i32, pid: i32, diff --git a/src/out/if_close.rs b/src/out/if_close.rs index 957d9c5..e856dce 100644 --- a/src/out/if_close.rs +++ b/src/out/if_close.rs @@ -6,7 +6,7 @@ pub struct IfClose {} impl IfClose { #[inline] - pub fn new() -> IfClose { + pub const fn new() -> IfClose { return IfClose {} } } diff --git a/src/out/if_openchat.rs b/src/out/if_openchat.rs index f859f08..7fa549d 100644 --- a/src/out/if_openchat.rs +++ b/src/out/if_openchat.rs @@ -8,7 +8,7 @@ pub struct IfOpenChat { impl IfOpenChat { #[inline] - pub fn new(component:i32) -> IfOpenChat { + pub const fn new(component:i32) -> IfOpenChat { return IfOpenChat { component, } diff --git a/src/out/if_openmain.rs b/src/out/if_openmain.rs index aaba0ff..539549d 100644 --- a/src/out/if_openmain.rs +++ b/src/out/if_openmain.rs @@ -8,7 +8,7 @@ pub struct IfOpenMain { impl IfOpenMain { #[inline] - pub fn new(component:i32) -> IfOpenMain { + pub const fn new(component:i32) -> IfOpenMain { return IfOpenMain { component, } diff --git a/src/out/if_openmainside.rs b/src/out/if_openmainside.rs index 0588ab4..87a0d10 100644 --- a/src/out/if_openmainside.rs +++ b/src/out/if_openmainside.rs @@ -9,7 +9,7 @@ pub struct IfOpenMainSide { impl IfOpenMainSide { #[inline] - pub fn new( + pub const fn new( main: i32, side: i32, ) -> IfOpenMainSide { diff --git a/src/out/if_openside.rs b/src/out/if_openside.rs index 0c2f58d..1573324 100644 --- a/src/out/if_openside.rs +++ b/src/out/if_openside.rs @@ -8,7 +8,7 @@ pub struct IfOpenSide { impl IfOpenSide { #[inline] - pub fn new(component:i32) -> IfOpenSide { + pub const fn new(component:i32) -> IfOpenSide { return IfOpenSide { component, } diff --git a/src/out/if_setanim.rs b/src/out/if_setanim.rs index ca6b9cb..ef53b7d 100644 --- a/src/out/if_setanim.rs +++ b/src/out/if_setanim.rs @@ -9,7 +9,7 @@ pub struct IfSetAnim { impl IfSetAnim { #[inline] - pub fn new( + pub const fn new( component: i32, seq: i32, ) -> IfSetAnim { diff --git a/src/out/if_setcolour.rs b/src/out/if_setcolour.rs index 1c2b1c2..75e5b7d 100644 --- a/src/out/if_setcolour.rs +++ b/src/out/if_setcolour.rs @@ -9,7 +9,7 @@ pub struct IfSetColour { impl IfSetColour { #[inline] - pub fn new( + pub const fn new( component: i32, colour: i32, ) -> IfSetColour { diff --git a/src/out/if_sethide.rs b/src/out/if_sethide.rs index 7e18f32..602e85b 100644 --- a/src/out/if_sethide.rs +++ b/src/out/if_sethide.rs @@ -9,7 +9,7 @@ pub struct IfSetHide { impl IfSetHide { #[inline] - pub fn new( + pub const fn new( component: i32, hidden: bool, ) -> IfSetHide { diff --git a/src/out/if_setmodel.rs b/src/out/if_setmodel.rs index 8f5c13f..7756b2c 100644 --- a/src/out/if_setmodel.rs +++ b/src/out/if_setmodel.rs @@ -9,7 +9,7 @@ pub struct IfSetModel { impl IfSetModel { #[inline] - pub fn new( + pub const fn new( component: i32, model: i32, ) -> IfSetModel { diff --git a/src/out/if_setnpchead.rs b/src/out/if_setnpchead.rs index 2d4e517..c100bda 100644 --- a/src/out/if_setnpchead.rs +++ b/src/out/if_setnpchead.rs @@ -9,7 +9,7 @@ pub struct IfSetNpcHead { impl IfSetNpcHead { #[inline] - pub fn new( + pub const fn new( component: i32, npc: i32, ) -> IfSetNpcHead { diff --git a/src/out/if_setobject.rs b/src/out/if_setobject.rs index e374d8e..c7ff302 100644 --- a/src/out/if_setobject.rs +++ b/src/out/if_setobject.rs @@ -10,7 +10,7 @@ pub struct IfSetObject { impl IfSetObject { #[inline] - pub fn new( + pub const fn new( component: i32, obj: i32, scale: i32, diff --git a/src/out/if_setplayerhead.rs b/src/out/if_setplayerhead.rs index ed5569a..4bd687a 100644 --- a/src/out/if_setplayerhead.rs +++ b/src/out/if_setplayerhead.rs @@ -8,7 +8,7 @@ pub struct IfSetPlayerHead { impl IfSetPlayerHead { #[inline] - pub fn new( + pub const fn new( component: i32, ) -> IfSetPlayerHead { return IfSetPlayerHead { diff --git a/src/out/if_setposition.rs b/src/out/if_setposition.rs index 8230f50..6f35166 100644 --- a/src/out/if_setposition.rs +++ b/src/out/if_setposition.rs @@ -10,7 +10,7 @@ pub struct IfSetPosition { impl IfSetPosition { #[inline] - pub fn new( + pub const fn new( component: i32, x: i32, y: i32, diff --git a/src/out/if_setrecol.rs b/src/out/if_setrecol.rs index 2b391ab..d48cafe 100644 --- a/src/out/if_setrecol.rs +++ b/src/out/if_setrecol.rs @@ -10,7 +10,7 @@ pub struct IfSetRecol { impl IfSetRecol { #[inline] - pub fn new( + pub const fn new( component: i32, src: i32, dst: i32, diff --git a/src/out/if_settab.rs b/src/out/if_settab.rs index b285d6e..0102d6b 100644 --- a/src/out/if_settab.rs +++ b/src/out/if_settab.rs @@ -9,7 +9,7 @@ pub struct IfSetTab { impl IfSetTab { #[inline] - pub fn new( + pub const fn new( component: i32, tab: i32, ) -> IfSetTab { diff --git a/src/out/if_settabactive.rs b/src/out/if_settabactive.rs index fd4da37..0d55973 100644 --- a/src/out/if_settabactive.rs +++ b/src/out/if_settabactive.rs @@ -8,7 +8,7 @@ pub struct IfSetTabActive { impl IfSetTabActive { #[inline] - pub fn new( + pub const fn new( tab: i32, ) -> IfSetTabActive { return IfSetTabActive { diff --git a/src/out/if_settext.rs b/src/out/if_settext.rs index fb9c566..fd9f8f0 100644 --- a/src/out/if_settext.rs +++ b/src/out/if_settext.rs @@ -9,7 +9,7 @@ pub struct IfSetText { impl IfSetText { #[inline] - pub fn new( + pub const fn new( component: i32, text: String, ) -> IfSetText { diff --git a/src/out/last_login_info.rs b/src/out/last_login_info.rs index 025bdac..51767ce 100644 --- a/src/out/last_login_info.rs +++ b/src/out/last_login_info.rs @@ -11,7 +11,7 @@ pub struct LastLoginInfo { impl LastLoginInfo { #[inline] - pub fn new( + pub const fn new( last_ip: i32, days_since_login: i32, days_since_recovery: i32, diff --git a/src/out/loc_addchange.rs b/src/out/loc_addchange.rs index 549148c..0a02fdb 100644 --- a/src/out/loc_addchange.rs +++ b/src/out/loc_addchange.rs @@ -11,7 +11,7 @@ pub struct LocAddChange { impl LocAddChange { #[inline] - pub fn new( + pub const fn new( coord: i32, loc: i32, shape: i32, diff --git a/src/out/loc_anim.rs b/src/out/loc_anim.rs index 188a423..104d696 100644 --- a/src/out/loc_anim.rs +++ b/src/out/loc_anim.rs @@ -11,7 +11,7 @@ pub struct LocAnim { impl LocAnim { #[inline] - pub fn new( + pub const fn new( coord: i32, shape: i32, angle: i32, diff --git a/src/out/loc_del.rs b/src/out/loc_del.rs index 0422bc6..0d60ac5 100644 --- a/src/out/loc_del.rs +++ b/src/out/loc_del.rs @@ -10,7 +10,7 @@ pub struct LocDel { impl LocDel { #[inline] - pub fn new( + pub const fn new( coord: i32, shape: i32, angle: i32, diff --git a/src/out/loc_merge.rs b/src/out/loc_merge.rs index 8cc91d7..1c407d8 100644 --- a/src/out/loc_merge.rs +++ b/src/out/loc_merge.rs @@ -21,7 +21,7 @@ pub struct LocMerge { impl LocMerge { #[inline] - pub fn new( + pub const fn new( src_x: i32, src_z: i32, shape: i32, diff --git a/src/out/logout.rs b/src/out/logout.rs index 4cbd828..15ae191 100644 --- a/src/out/logout.rs +++ b/src/out/logout.rs @@ -6,7 +6,7 @@ pub struct Logout {} impl Logout { #[inline] - pub fn new() -> Logout { + pub const fn new() -> Logout { return Logout {} } } diff --git a/src/out/map_anim.rs b/src/out/map_anim.rs index 2ff4583..962f2ca 100644 --- a/src/out/map_anim.rs +++ b/src/out/map_anim.rs @@ -11,7 +11,7 @@ pub struct MapAnim { impl MapAnim { #[inline] - pub fn new( + pub const fn new( coord: i32, spotanim: i32, height: i32, diff --git a/src/out/map_projanim.rs b/src/out/map_projanim.rs index 4402b0d..61d71ef 100644 --- a/src/out/map_projanim.rs +++ b/src/out/map_projanim.rs @@ -21,7 +21,7 @@ pub struct MapProjAnim { impl MapProjAnim { #[inline] - pub fn new( + pub const fn new( src_x: i32, src_z: i32, dst_x: i32, diff --git a/src/out/message_game.rs b/src/out/message_game.rs index b80507c..2d0bc51 100644 --- a/src/out/message_game.rs +++ b/src/out/message_game.rs @@ -8,7 +8,7 @@ pub struct MessageGame { impl MessageGame { #[inline] - pub fn new(msg: String) -> MessageGame { + pub const fn new(msg: String) -> MessageGame { return MessageGame { msg, } diff --git a/src/out/message_private.rs b/src/out/message_private.rs index 25cf389..619843c 100644 --- a/src/out/message_private.rs +++ b/src/out/message_private.rs @@ -1,7 +1,7 @@ use crate::message::MessageEncoder; -use crate::wordpack::WordPack; use crate::packet::Packet; use crate::prot::ServerInternalProt; +use crate::wordpack::WordPack; pub struct MessagePrivateOut { from: i64, @@ -12,7 +12,7 @@ pub struct MessagePrivateOut { impl MessagePrivateOut { #[inline] - pub fn new( + pub const fn new( from: i64, id: i32, staff_mod_level: i32, diff --git a/src/out/midi_jingle.rs b/src/out/midi_jingle.rs index d35e3c8..3a38445 100644 --- a/src/out/midi_jingle.rs +++ b/src/out/midi_jingle.rs @@ -9,7 +9,7 @@ pub struct MidiJingle { impl MidiJingle { #[inline] - pub fn new( + pub const fn new( delay: i32, data: Vec, ) -> MidiJingle { diff --git a/src/out/midi_song.rs b/src/out/midi_song.rs index 34a3933..e66a511 100644 --- a/src/out/midi_song.rs +++ b/src/out/midi_song.rs @@ -10,7 +10,7 @@ pub struct MidiSong { impl MidiSong { #[inline] - pub fn new( + pub const fn new( name: String, crc: i32, length: i32, diff --git a/src/out/obj_add.rs b/src/out/obj_add.rs index 4a8b899..dbf8b47 100644 --- a/src/out/obj_add.rs +++ b/src/out/obj_add.rs @@ -10,7 +10,7 @@ pub struct ObjAdd { impl ObjAdd { #[inline] - pub fn new( + pub const fn new( coord: i32, obj: i32, count: i32, diff --git a/src/out/obj_count.rs b/src/out/obj_count.rs index d35131f..7173928 100644 --- a/src/out/obj_count.rs +++ b/src/out/obj_count.rs @@ -11,7 +11,7 @@ pub struct ObjCount { impl ObjCount { #[inline] - pub fn new( + pub const fn new( coord: i32, obj: i32, old_count: i32, diff --git a/src/out/obj_del.rs b/src/out/obj_del.rs index 1f76e93..6fd1e37 100644 --- a/src/out/obj_del.rs +++ b/src/out/obj_del.rs @@ -9,7 +9,7 @@ pub struct ObjDel { impl ObjDel { #[inline] - pub fn new( + pub const fn new( coord: i32, obj: i32, ) -> ObjDel { diff --git a/src/out/obj_reveal.rs b/src/out/obj_reveal.rs index 64176fd..1328258 100644 --- a/src/out/obj_reveal.rs +++ b/src/out/obj_reveal.rs @@ -11,7 +11,7 @@ pub struct ObjReveal { impl ObjReveal { #[inline] - pub fn new( + pub const fn new( coord: i32, obj: i32, count: i32, diff --git a/src/out/rebuild_normal.rs b/src/out/rebuild_normal.rs index 32f7015..059c4d5 100644 --- a/src/out/rebuild_normal.rs +++ b/src/out/rebuild_normal.rs @@ -12,7 +12,7 @@ pub struct RebuildNormal { impl RebuildNormal { #[inline] - pub fn new( + pub const fn new( x: i32, z: i32, squares: Vec, diff --git a/src/out/reset_anims.rs b/src/out/reset_anims.rs index e0ed856..eb2429d 100644 --- a/src/out/reset_anims.rs +++ b/src/out/reset_anims.rs @@ -6,7 +6,7 @@ pub struct ResetAnims {} impl ResetAnims { #[inline] - pub fn new() -> ResetAnims { + pub const fn new() -> ResetAnims { return ResetAnims {} } } diff --git a/src/out/reset_clientvarcache.rs b/src/out/reset_clientvarcache.rs index 126ea43..4e34338 100644 --- a/src/out/reset_clientvarcache.rs +++ b/src/out/reset_clientvarcache.rs @@ -6,7 +6,7 @@ pub struct ResetClientVarCache {} impl ResetClientVarCache { #[inline] - pub fn new() -> ResetClientVarCache { + pub const fn new() -> ResetClientVarCache { return ResetClientVarCache {} } } diff --git a/src/out/set_multiway.rs b/src/out/set_multiway.rs index 43a9e95..1a3f9a9 100644 --- a/src/out/set_multiway.rs +++ b/src/out/set_multiway.rs @@ -8,7 +8,7 @@ pub struct SetMultiway { impl SetMultiway { #[inline] - pub fn new(hidden: bool) -> SetMultiway { + pub const fn new(hidden: bool) -> SetMultiway { return SetMultiway { hidden, } diff --git a/src/out/synth_sound.rs b/src/out/synth_sound.rs index a9d0bd1..da948c5 100644 --- a/src/out/synth_sound.rs +++ b/src/out/synth_sound.rs @@ -10,7 +10,7 @@ pub struct SynthSound { impl SynthSound { #[inline] - pub fn new( + pub const fn new( synth: i32, loops: i32, delay: i32, diff --git a/src/out/tut_flash.rs b/src/out/tut_flash.rs index 73570b4..1a1cee9 100644 --- a/src/out/tut_flash.rs +++ b/src/out/tut_flash.rs @@ -8,7 +8,7 @@ pub struct TutFlash { impl TutFlash { #[inline] - pub fn new( + pub const fn new( tab: i32, ) -> TutFlash { return TutFlash { diff --git a/src/out/tut_open.rs b/src/out/tut_open.rs index fceead9..6edaf3f 100644 --- a/src/out/tut_open.rs +++ b/src/out/tut_open.rs @@ -8,7 +8,7 @@ pub struct TutOpen { impl TutOpen { #[inline] - pub fn new( + pub const fn new( component: i32, ) -> TutOpen { return TutOpen { diff --git a/src/out/unset_map_flag.rs b/src/out/unset_map_flag.rs index 1127e37..9369c54 100644 --- a/src/out/unset_map_flag.rs +++ b/src/out/unset_map_flag.rs @@ -6,7 +6,7 @@ pub struct UnsetMapFlag {} impl UnsetMapFlag { #[inline] - pub fn new() -> UnsetMapFlag { + pub const fn new() -> UnsetMapFlag { return UnsetMapFlag {} } } diff --git a/src/out/update_friendlist.rs b/src/out/update_friendlist.rs index 8a6f99d..c1a26fb 100644 --- a/src/out/update_friendlist.rs +++ b/src/out/update_friendlist.rs @@ -9,7 +9,7 @@ pub struct UpdateFriendList { impl UpdateFriendList { #[inline] - pub fn new(name: i64, node: i32) -> UpdateFriendList { + pub const fn new(name: i64, node: i32) -> UpdateFriendList { return UpdateFriendList { name, node, diff --git a/src/out/update_ignorelist.rs b/src/out/update_ignorelist.rs index fac1fc0..d19ae66 100644 --- a/src/out/update_ignorelist.rs +++ b/src/out/update_ignorelist.rs @@ -8,7 +8,7 @@ pub struct UpdateIgnoreList { impl UpdateIgnoreList { #[inline] - pub fn new(names: Vec) -> UpdateIgnoreList { + pub const fn new(names: Vec) -> UpdateIgnoreList { return UpdateIgnoreList { names, } diff --git a/src/out/update_inv_full.rs b/src/out/update_inv_full.rs index 6ab706c..7d34044 100644 --- a/src/out/update_inv_full.rs +++ b/src/out/update_inv_full.rs @@ -10,7 +10,7 @@ pub struct UpdateInvFull { impl UpdateInvFull { #[inline] - pub fn new( + pub const fn new( size: i32, component: i32, objs: Vec, diff --git a/src/out/update_inv_partial.rs b/src/out/update_inv_partial.rs index b14d905..8c9c04f 100644 --- a/src/out/update_inv_partial.rs +++ b/src/out/update_inv_partial.rs @@ -10,7 +10,7 @@ pub struct UpdateInvPartial { impl UpdateInvPartial { #[inline] - pub fn new( + pub const fn new( component: i32, slots: Vec, objs: Vec, diff --git a/src/out/update_inv_stop_transmit.rs b/src/out/update_inv_stop_transmit.rs index 63815a0..48523af 100644 --- a/src/out/update_inv_stop_transmit.rs +++ b/src/out/update_inv_stop_transmit.rs @@ -8,7 +8,7 @@ pub struct UpdateInvStopTransmit { impl UpdateInvStopTransmit { #[inline] - pub fn new( + pub const fn new( component: i32, ) -> UpdateInvStopTransmit { return UpdateInvStopTransmit { diff --git a/src/out/update_pid.rs b/src/out/update_pid.rs index f0f0e5f..4fafe75 100644 --- a/src/out/update_pid.rs +++ b/src/out/update_pid.rs @@ -8,7 +8,7 @@ pub struct UpdatePid { impl UpdatePid { #[inline] - pub fn new( + pub const fn new( pid: i32, ) -> UpdatePid { return UpdatePid { diff --git a/src/out/update_reboot_timer.rs b/src/out/update_reboot_timer.rs index 515bdd3..a84a344 100644 --- a/src/out/update_reboot_timer.rs +++ b/src/out/update_reboot_timer.rs @@ -8,7 +8,7 @@ pub struct UpdateRebootTimer { impl UpdateRebootTimer { #[inline] - pub fn new( + pub const fn new( ticks: i32, ) -> UpdateRebootTimer { return UpdateRebootTimer { diff --git a/src/out/update_runenergy.rs b/src/out/update_runenergy.rs index 796d143..45c66de 100644 --- a/src/out/update_runenergy.rs +++ b/src/out/update_runenergy.rs @@ -8,7 +8,7 @@ pub struct UpdateRunEnergy { impl UpdateRunEnergy { #[inline] - pub fn new( + pub const fn new( energy: i32, ) -> UpdateRunEnergy { return UpdateRunEnergy { diff --git a/src/out/update_runweight.rs b/src/out/update_runweight.rs index 467af6e..5f7931e 100644 --- a/src/out/update_runweight.rs +++ b/src/out/update_runweight.rs @@ -8,7 +8,7 @@ pub struct UpdateRunWeight { impl UpdateRunWeight { #[inline] - pub fn new( + pub const fn new( kg: i32, ) -> UpdateRunWeight { return UpdateRunWeight { diff --git a/src/out/update_stat.rs b/src/out/update_stat.rs index 1448e71..6cc9734 100644 --- a/src/out/update_stat.rs +++ b/src/out/update_stat.rs @@ -10,7 +10,7 @@ pub struct UpdateStat { impl UpdateStat { #[inline] - pub fn new( + pub const fn new( stat: i32, experience: i32, level: i32, diff --git a/src/out/update_zone_full_follows.rs b/src/out/update_zone_full_follows.rs index b467665..cb3890b 100644 --- a/src/out/update_zone_full_follows.rs +++ b/src/out/update_zone_full_follows.rs @@ -12,7 +12,7 @@ pub struct UpdateZoneFullFollows { impl UpdateZoneFullFollows { #[inline] - pub fn new( + pub const fn new( x: i32, z: i32, origin_x: i32, diff --git a/src/out/update_zone_partial_enclosed.rs b/src/out/update_zone_partial_enclosed.rs index 8e5f722..9992002 100644 --- a/src/out/update_zone_partial_enclosed.rs +++ b/src/out/update_zone_partial_enclosed.rs @@ -13,7 +13,7 @@ pub struct UpdateZonePartialEnclosed { impl UpdateZonePartialEnclosed { #[inline] - pub fn new( + pub const fn new( x: i32, z: i32, origin_x: i32, diff --git a/src/out/update_zone_partial_follows.rs b/src/out/update_zone_partial_follows.rs index c156e39..5af20e3 100644 --- a/src/out/update_zone_partial_follows.rs +++ b/src/out/update_zone_partial_follows.rs @@ -12,7 +12,7 @@ pub struct UpdateZonePartialFollows { impl UpdateZonePartialFollows { #[inline] - pub fn new( + pub const fn new( x: i32, z: i32, origin_x: i32, diff --git a/src/out/varp_large.rs b/src/out/varp_large.rs index 2ef13b9..18543e0 100644 --- a/src/out/varp_large.rs +++ b/src/out/varp_large.rs @@ -9,7 +9,7 @@ pub struct VarpLarge { impl VarpLarge { #[inline] - pub fn new( + pub const fn new( varp: i32, value: i32, ) -> VarpLarge { diff --git a/src/out/varp_small.rs b/src/out/varp_small.rs index e0fa36a..2b48c9c 100644 --- a/src/out/varp_small.rs +++ b/src/out/varp_small.rs @@ -9,7 +9,7 @@ pub struct VarpSmall { impl VarpSmall { #[inline] - pub fn new( + pub const fn new( varp: i32, value: i32, ) -> VarpSmall { diff --git a/src/player.rs b/src/player.rs index 60b6c4d..b4f6993 100644 --- a/src/player.rs +++ b/src/player.rs @@ -2,9 +2,9 @@ use crate::build::BuildArea; use crate::coord::CoordGrid; use crate::message::MessageEncoder; use crate::packet::Packet; +use crate::pool::PacketPool; use crate::visibility::Visibility; use std::collections::VecDeque; -use crate::pool::PacketPool; #[derive(Clone)] pub struct Player { From 0e3a5a4f9c4037adc6c132c373efc5d11ac34572 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 1 Apr 2025 01:53:49 -0400 Subject: [PATCH 13/14] feat: optimizations --- src/in/anticheat.rs | 90 +++++++++++++++++++++++------------ src/in/close_modal.rs | 6 ++- src/in/idle_timer.rs | 6 ++- src/in/no_timeout.rs | 6 ++- src/lib.rs | 10 ++-- src/out/message_private.rs | 8 ++-- src/out/midi_jingle.rs | 2 +- src/out/rebuild_normal.rs | 4 +- src/out/update_inv_full.rs | 26 ++++------ src/out/update_inv_partial.rs | 23 ++++----- src/wordpack.rs | 4 +- tests/wordpack.rs | 4 +- 12 files changed, 104 insertions(+), 85 deletions(-) diff --git a/src/in/anticheat.rs b/src/in/anticheat.rs index 2a7a1bb..5e96f6b 100644 --- a/src/in/anticheat.rs +++ b/src/in/anticheat.rs @@ -7,8 +7,10 @@ use wasm_bindgen::prelude::wasm_bindgen; pub struct AnticheatOp1 {} impl AnticheatOp1 { + const DEFAULT: AnticheatOp1 = AnticheatOp1::new(); + #[inline] - pub fn new() -> AnticheatOp1 { + pub const fn new() -> AnticheatOp1 { return AnticheatOp1 {}; } } @@ -21,7 +23,7 @@ impl MessageDecoder for AnticheatOp1 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatOp1 { - return AnticheatOp1::new(); + return AnticheatOp1::DEFAULT; } } @@ -31,8 +33,10 @@ impl MessageDecoder for AnticheatOp1 { pub struct AnticheatOp2 {} impl AnticheatOp2 { + const DEFAULT: AnticheatOp2 = AnticheatOp2::new(); + #[inline] - pub fn new() -> AnticheatOp2 { + pub const fn new() -> AnticheatOp2 { return AnticheatOp2 {}; } } @@ -45,7 +49,7 @@ impl MessageDecoder for AnticheatOp2 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatOp2 { - return AnticheatOp2::new(); + return AnticheatOp2::DEFAULT; } } @@ -55,8 +59,10 @@ impl MessageDecoder for AnticheatOp2 { pub struct AnticheatOp3 {} impl AnticheatOp3 { + const DEFAULT: AnticheatOp3 = AnticheatOp3::new(); + #[inline] - pub fn new() -> AnticheatOp3 { + pub const fn new() -> AnticheatOp3 { return AnticheatOp3 {}; } } @@ -69,7 +75,7 @@ impl MessageDecoder for AnticheatOp3 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatOp3 { - return AnticheatOp3::new(); + return AnticheatOp3::DEFAULT; } } @@ -79,8 +85,10 @@ impl MessageDecoder for AnticheatOp3 { pub struct AnticheatOp4 {} impl AnticheatOp4 { + const DEFAULT: AnticheatOp4 = AnticheatOp4::new(); + #[inline] - pub fn new() -> AnticheatOp4 { + pub const fn new() -> AnticheatOp4 { return AnticheatOp4 {}; } } @@ -93,7 +101,7 @@ impl MessageDecoder for AnticheatOp4 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatOp4 { - return AnticheatOp4::new(); + return AnticheatOp4::DEFAULT; } } @@ -103,8 +111,10 @@ impl MessageDecoder for AnticheatOp4 { pub struct AnticheatOp5 {} impl AnticheatOp5 { + const DEFAULT: AnticheatOp5 = AnticheatOp5::new(); + #[inline] - pub fn new() -> AnticheatOp5 { + pub const fn new() -> AnticheatOp5 { return AnticheatOp5 {}; } } @@ -117,7 +127,7 @@ impl MessageDecoder for AnticheatOp5 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatOp5 { - return AnticheatOp5::new(); + return AnticheatOp5::DEFAULT; } } @@ -127,8 +137,10 @@ impl MessageDecoder for AnticheatOp5 { pub struct AnticheatOp6 {} impl AnticheatOp6 { + const DEFAULT: AnticheatOp6 = AnticheatOp6::new(); + #[inline] - pub fn new() -> AnticheatOp6 { + pub const fn new() -> AnticheatOp6 { return AnticheatOp6 {}; } } @@ -141,7 +153,7 @@ impl MessageDecoder for AnticheatOp6 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatOp6 { - return AnticheatOp6::new(); + return AnticheatOp6::DEFAULT; } } @@ -151,8 +163,10 @@ impl MessageDecoder for AnticheatOp6 { pub struct AnticheatOp7 {} impl AnticheatOp7 { + const DEFAULT: AnticheatOp7 = AnticheatOp7::new(); + #[inline] - pub fn new() -> AnticheatOp7 { + pub const fn new() -> AnticheatOp7 { return AnticheatOp7 {}; } } @@ -165,7 +179,7 @@ impl MessageDecoder for AnticheatOp7 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatOp7 { - return AnticheatOp7::new(); + return AnticheatOp7::DEFAULT; } } @@ -175,8 +189,10 @@ impl MessageDecoder for AnticheatOp7 { pub struct AnticheatOp8 {} impl AnticheatOp8 { + const DEFAULT: AnticheatOp8 = AnticheatOp8::new(); + #[inline] - pub fn new() -> AnticheatOp8 { + pub const fn new() -> AnticheatOp8 { return AnticheatOp8 {}; } } @@ -189,7 +205,7 @@ impl MessageDecoder for AnticheatOp8 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatOp8 { - return AnticheatOp8::new(); + return AnticheatOp8::DEFAULT; } } @@ -199,8 +215,10 @@ impl MessageDecoder for AnticheatOp8 { pub struct AnticheatOp9 {} impl AnticheatOp9 { + const DEFAULT: AnticheatOp9 = AnticheatOp9::new(); + #[inline] - pub fn new() -> AnticheatOp9 { + pub const fn new() -> AnticheatOp9 { return AnticheatOp9 {}; } } @@ -213,7 +231,7 @@ impl MessageDecoder for AnticheatOp9 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatOp9 { - return AnticheatOp9::new(); + return AnticheatOp9::DEFAULT; } } @@ -223,8 +241,10 @@ impl MessageDecoder for AnticheatOp9 { pub struct AnticheatCycle1 {} impl AnticheatCycle1 { + const DEFAULT: AnticheatCycle1 = AnticheatCycle1::new(); + #[inline] - pub fn new() -> AnticheatCycle1 { + pub const fn new() -> AnticheatCycle1 { return AnticheatCycle1 {}; } } @@ -237,7 +257,7 @@ impl MessageDecoder for AnticheatCycle1 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatCycle1 { - return AnticheatCycle1::new(); + return AnticheatCycle1::DEFAULT; } } @@ -247,8 +267,10 @@ impl MessageDecoder for AnticheatCycle1 { pub struct AnticheatCycle2 {} impl AnticheatCycle2 { + const DEFAULT: AnticheatCycle2 = AnticheatCycle2::new(); + #[inline] - pub fn new() -> AnticheatCycle2 { + pub const fn new() -> AnticheatCycle2 { return AnticheatCycle2 {}; } } @@ -261,7 +283,7 @@ impl MessageDecoder for AnticheatCycle2 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatCycle2 { - return AnticheatCycle2::new(); + return AnticheatCycle2::DEFAULT; } } @@ -271,8 +293,10 @@ impl MessageDecoder for AnticheatCycle2 { pub struct AnticheatCycle3 {} impl AnticheatCycle3 { + const DEFAULT: AnticheatCycle3 = AnticheatCycle3::new(); + #[inline] - pub fn new() -> AnticheatCycle3 { + pub const fn new() -> AnticheatCycle3 { return AnticheatCycle3 {}; } } @@ -285,7 +309,7 @@ impl MessageDecoder for AnticheatCycle3 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatCycle3 { - return AnticheatCycle3::new(); + return AnticheatCycle3::DEFAULT; } } @@ -295,8 +319,10 @@ impl MessageDecoder for AnticheatCycle3 { pub struct AnticheatCycle4 {} impl AnticheatCycle4 { + const DEFAULT: AnticheatCycle4 = AnticheatCycle4::new(); + #[inline] - pub fn new() -> AnticheatCycle4 { + pub const fn new() -> AnticheatCycle4 { return AnticheatCycle4 {}; } } @@ -309,7 +335,7 @@ impl MessageDecoder for AnticheatCycle4 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatCycle4 { - return AnticheatCycle4::new(); + return AnticheatCycle4::DEFAULT; } } @@ -319,8 +345,10 @@ impl MessageDecoder for AnticheatCycle4 { pub struct AnticheatCycle5 {} impl AnticheatCycle5 { + const DEFAULT: AnticheatCycle5 = AnticheatCycle5::new(); + #[inline] - pub fn new() -> AnticheatCycle5 { + pub const fn new() -> AnticheatCycle5 { return AnticheatCycle5 {}; } } @@ -333,7 +361,7 @@ impl MessageDecoder for AnticheatCycle5 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatCycle5 { - return AnticheatCycle5::new(); + return AnticheatCycle5::DEFAULT; } } @@ -343,8 +371,10 @@ impl MessageDecoder for AnticheatCycle5 { pub struct AnticheatCycle6 {} impl AnticheatCycle6 { + const DEFAULT: AnticheatCycle6 = AnticheatCycle6::new(); + #[inline] - pub fn new() -> AnticheatCycle6 { + pub const fn new() -> AnticheatCycle6 { return AnticheatCycle6 {}; } } @@ -357,6 +387,6 @@ impl MessageDecoder for AnticheatCycle6 { #[inline] fn decode(_: ClientProt, _: Packet) -> AnticheatCycle6 { - return AnticheatCycle6::new(); + return AnticheatCycle6::DEFAULT; } } \ No newline at end of file diff --git a/src/in/close_modal.rs b/src/in/close_modal.rs index 8c0bd58..9e6bc87 100644 --- a/src/in/close_modal.rs +++ b/src/in/close_modal.rs @@ -7,8 +7,10 @@ use wasm_bindgen::prelude::wasm_bindgen; pub struct CloseModal {} impl CloseModal { + const DEFAULT: CloseModal = CloseModal::new(); + #[inline] - pub fn new() -> CloseModal { + pub const fn new() -> CloseModal { return CloseModal {} } } @@ -21,6 +23,6 @@ impl MessageDecoder for CloseModal { #[inline] fn decode(_: ClientProt, _: Packet) -> CloseModal { - return CloseModal::new(); + return CloseModal::DEFAULT; } } \ No newline at end of file diff --git a/src/in/idle_timer.rs b/src/in/idle_timer.rs index 94fd29c..495089d 100644 --- a/src/in/idle_timer.rs +++ b/src/in/idle_timer.rs @@ -7,8 +7,10 @@ use wasm_bindgen::prelude::wasm_bindgen; pub struct IdleTimer {} impl IdleTimer { + const DEFAULT: IdleTimer = IdleTimer::new(); + #[inline] - pub fn new() -> IdleTimer { + pub const fn new() -> IdleTimer { return IdleTimer {} } } @@ -21,6 +23,6 @@ impl MessageDecoder for IdleTimer { #[inline] fn decode(_: ClientProt, _: Packet) -> IdleTimer { - return IdleTimer::new(); + return IdleTimer::DEFAULT; } } \ No newline at end of file diff --git a/src/in/no_timeout.rs b/src/in/no_timeout.rs index 452a351..a2c581d 100644 --- a/src/in/no_timeout.rs +++ b/src/in/no_timeout.rs @@ -7,8 +7,10 @@ use wasm_bindgen::prelude::wasm_bindgen; pub struct NoTimeout {} impl NoTimeout { + const DEFAULT: NoTimeout = NoTimeout::new(); + #[inline] - pub fn new() -> NoTimeout { + pub const fn new() -> NoTimeout { return NoTimeout {}; } } @@ -21,6 +23,6 @@ impl MessageDecoder for NoTimeout { #[inline] fn decode(_: ClientProt, _: Packet) -> NoTimeout { - return NoTimeout::new(); + return NoTimeout::DEFAULT; } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index a353bc1..182c33f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -572,7 +572,7 @@ write!(logout, "logout", Logout, (), ()); write!(map_anim, "mapAnim", MapAnim, (coord: i32, spotanim: i32, height: i32, delay: i32), (coord, spotanim, height, delay)); write!(map_projanim, "mapProjAnim", MapProjAnim, (srcX: i32, srcZ: i32, dstX: i32, dstZ: i32, target: i32, spotanim: i32, srcHeight: i32, dstHeight: i32, start: i32, end: i32, peak: i32, arc: i32), (srcX, srcZ, dstX, dstZ, target, spotanim, srcHeight, dstHeight, start, end, peak, arc)); write!(message_game, "messageGame", MessageGame, (msg: String), (msg)); -write!(message_private_out, "messagePrivateOut", MessagePrivateOut, (from: i64, id: i32, staffModLevel: i32, msg: String), (from, id, staffModLevel, msg)); +write!(message_private_out, "messagePrivateOut", MessagePrivateOut, (from: i64, id: i32, staffModLevel: i32, msg: Vec), (from, id, staffModLevel, msg)); buffer!(midi_jingle, "midiJingle", MidiJingle, (delay: i32, data: Vec), (delay, data)); buffer!(midi_song, "midiSong", MidiSong, (name: String, crc: i32, length: i32), (name, crc, length)); write!(obj_add, "objAdd", ObjAdd, (coord: i32, obj: i32, count: i32), (coord, obj, count)); @@ -589,8 +589,8 @@ buffer!(tut_open, "tutOpen", TutOpen, (component: i32), (component)); write!(unset_map_flag, "unsetMapFlag", UnsetMapFlag, (), ()); buffer!(update_friendlist, "updateFriendList", UpdateFriendList, (name: i64, node: i32), (name, node)); buffer!(update_ignorelist, "updateIgnoreList", UpdateIgnoreList, (names: Vec), (names)); -write!(update_inv_full, "updateInvFull", UpdateInvFull, (size: i32, component: i32, objs: Vec), (size, component, objs)); -write!(update_inv_partial, "updateInvPartial", UpdateInvPartial, (component: i32, slots: Vec, objs: Vec), (component, slots, objs)); +write!(update_inv_full, "updateInvFull", UpdateInvFull, (size: i32, component: i32, inv: Vec), (size, component, inv)); +write!(update_inv_partial, "updateInvPartial", UpdateInvPartial, (component: i32, slots: Vec, inv: Vec), (component, slots, inv)); write!(update_inv_stop_transmit, "updateInvStopTransmit", UpdateInvStopTransmit, (component: i32), (component)); write!(update_pid, "updatePid", UpdatePid, (pid: i32), (pid)); // todo: what should priority be? buffer!(update_reboot_timer, "updateRebootTimer", UpdateRebootTimer, (ticks: i32), (ticks)); // todo: what should priority be? @@ -813,8 +813,8 @@ pub unsafe fn is_buffer_full(pid: i32) -> bool { } #[wasm_bindgen(js_name = unpackWords)] -pub unsafe fn unpack_words(bytes: Vec, length: usize) -> String { - return WORD_PACK.unpack(Packet::from(bytes), length); +pub unsafe fn unpack_words(bytes: Vec) -> String { + return WORD_PACK.unpack(Packet::from(bytes)); } #[wasm_bindgen(js_name = packWords)] diff --git a/src/out/message_private.rs b/src/out/message_private.rs index 619843c..a32d792 100644 --- a/src/out/message_private.rs +++ b/src/out/message_private.rs @@ -1,13 +1,12 @@ use crate::message::MessageEncoder; use crate::packet::Packet; use crate::prot::ServerInternalProt; -use crate::wordpack::WordPack; pub struct MessagePrivateOut { from: i64, id: i32, staff_mod_level: i32, - msg: String, + msg: Vec, } impl MessagePrivateOut { @@ -16,7 +15,7 @@ impl MessagePrivateOut { from: i64, id: i32, staff_mod_level: i32, - msg: String, + msg: Vec, ) -> MessagePrivateOut { return MessagePrivateOut { from, @@ -48,8 +47,7 @@ impl MessageEncoder for MessagePrivateOut { buf.p8(self.from); buf.p4(self.id); buf.p1(staff_mod_level); - let bytes: Vec = unsafe { WordPack::new().pack(self.msg.clone()) }; - buf.pdata(&bytes, 0, bytes.len()) + buf.pdata(&self.msg, 0, self.msg.len()) } #[inline] diff --git a/src/out/midi_jingle.rs b/src/out/midi_jingle.rs index 3a38445..afed196 100644 --- a/src/out/midi_jingle.rs +++ b/src/out/midi_jingle.rs @@ -39,6 +39,6 @@ impl MessageEncoder for MidiJingle { #[inline] fn test(&self) -> usize { - return 6 + self.data.len(); + return 2 + self.data.len(); } } \ No newline at end of file diff --git a/src/out/rebuild_normal.rs b/src/out/rebuild_normal.rs index 059c4d5..53c0706 100644 --- a/src/out/rebuild_normal.rs +++ b/src/out/rebuild_normal.rs @@ -45,9 +45,7 @@ impl MessageEncoder for RebuildNormal { buf.p2(self.x); buf.p2(self.z); for index in 0..self.squares.len() { - let mapsquare: u16 = unsafe { *self.squares.as_ptr().add(index) }; - buf.p1(((mapsquare >> 8) & 0xff) as i32); - buf.p1((mapsquare & 0xff) as i32); + buf.p2(unsafe { *self.squares.as_ptr().add(index) as i32 }); buf.p4(unsafe { *self.maps.as_ptr().add(index) }); buf.p4(unsafe { *self.locs.as_ptr().add(index) }); } diff --git a/src/out/update_inv_full.rs b/src/out/update_inv_full.rs index 7d34044..db2d49d 100644 --- a/src/out/update_inv_full.rs +++ b/src/out/update_inv_full.rs @@ -5,7 +5,7 @@ use crate::prot::ServerInternalProt; pub struct UpdateInvFull { size: i32, component: i32, - objs: Vec, + inv: Vec, } impl UpdateInvFull { @@ -13,12 +13,12 @@ impl UpdateInvFull { pub const fn new( size: i32, component: i32, - objs: Vec, + inv: Vec, ) -> UpdateInvFull { return UpdateInvFull { size, component, - objs, + inv, } } } @@ -39,8 +39,7 @@ impl MessageEncoder for UpdateInvFull { // todo: size should be the index of the last non-empty slot buf.p2(self.component); buf.p1(self.size); - for slot in 0..self.size { - let packed: i64 = self.objs[slot as usize]; + for &packed in &self.inv[..self.size as usize] { let obj: i32 = (packed >> 31) as i32; if obj != -1 { let count: i32 = (packed & 0x7fffffff) as i32; @@ -60,23 +59,16 @@ impl MessageEncoder for UpdateInvFull { #[inline] fn test(&self) -> usize { - let mut length: usize = 0; - length += 3; - for slot in 0..self.size { - let packed: i64 = self.objs[slot as usize]; + let mut length: usize = 3; + for &packed in &self.inv[..self.size as usize] { let obj: i32 = (packed >> 31) as i32; if obj != -1 { - let count: i32 = (packed & 0x7fffffff) as i32; - length += 2; - if count >= 0xff { - length += 5; - } else { - length += 1; - } + let count = (packed & 0x7fffffff) as i32; + length += 2 + if count >= 0xff { 5 } else { 1 }; } else { length += 3; } } - return length; + return length } } \ No newline at end of file diff --git a/src/out/update_inv_partial.rs b/src/out/update_inv_partial.rs index 8c9c04f..3ef2a26 100644 --- a/src/out/update_inv_partial.rs +++ b/src/out/update_inv_partial.rs @@ -5,7 +5,7 @@ use crate::prot::ServerInternalProt; pub struct UpdateInvPartial { component: i32, slots: Vec, - objs: Vec, + inv: Vec, } impl UpdateInvPartial { @@ -13,12 +13,12 @@ impl UpdateInvPartial { pub const fn new( component: i32, slots: Vec, - objs: Vec, + inv: Vec, ) -> UpdateInvPartial { return UpdateInvPartial { component, slots, - objs, + inv, } } } @@ -38,8 +38,8 @@ impl MessageEncoder for UpdateInvPartial { fn encode(&self, buf: &mut Packet) { // todo: size should be the index of the last non-empty slot buf.p2(self.component); - for &slot in self.slots.iter() { - let packed: i64 = self.objs[slot as usize]; + for &slot in &self.slots { + let packed: i64 = self.inv[slot as usize]; let obj: i32 = (packed >> 31) as i32; buf.p1(slot); if obj != -1 { @@ -60,19 +60,14 @@ impl MessageEncoder for UpdateInvPartial { #[inline] fn test(&self) -> usize { - let mut length: usize = 0; - length += 2; - for &slot in self.slots.iter() { - let packed: i64 = self.objs[slot as usize]; + let mut length: usize = 2; + for &slot in &self.slots { + let packed: i64 = self.inv[slot as usize]; let obj: i32 = (packed >> 31) as i32; length += 1; if obj != -1 { let count: i32 = (packed & 0x7fffffff) as i32; - if count >= 0xff { - length += 5; - } else { - length += 1; - } + length += if count >= 0xff { 5 } else { 1 }; } else { length += 3; } diff --git a/src/wordpack.rs b/src/wordpack.rs index cdf7a3b..c16818e 100644 --- a/src/wordpack.rs +++ b/src/wordpack.rs @@ -24,12 +24,12 @@ impl WordPack { } #[inline] - pub unsafe fn unpack(&mut self, mut packet: Packet, length: usize) -> String { + pub unsafe fn unpack(&mut self, mut packet: Packet) -> String { self.unpack.clear(); let mut carry: i32 = -1; - for _ in 0..length { + for _ in 0..packet.len() { if self.unpack.len() >= 80 { break; } diff --git a/tests/wordpack.rs b/tests/wordpack.rs index ded4c63..4b1cca7 100644 --- a/tests/wordpack.rs +++ b/tests/wordpack.rs @@ -4,13 +4,13 @@ use rsbuf::wordpack::WordPack; #[test] fn test_unpack_test() { let packet: Packet = Packet::from(vec![33, 130]); - unsafe { assert_eq!("Test", WordPack::new().unpack(packet, 2)) }; + unsafe { assert_eq!("Test", WordPack::new().unpack(packet)) }; } #[test] fn test_unpack_zezima() { let packet: Packet = Packet::from(vec![221, 29, 213, 208, 48]); - unsafe { assert_eq!("Zezima ", WordPack::new().unpack(packet, 5)) }; + unsafe { assert_eq!("Zezima ", WordPack::new().unpack(packet)) }; } #[test] From 309d84006683ac624af336ec8abc16a7ae4683fb Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 1 Apr 2025 01:58:36 -0400 Subject: [PATCH 14/14] chore: update project info --- Cargo.lock | 2 +- Cargo.toml | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55d9d32..c3de89f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -605,7 +605,7 @@ dependencies = [ [[package]] name = "rsbuf" -version = "225.1.7" +version = "225.1.8" dependencies = [ "criterion", "getrandom", diff --git a/Cargo.toml b/Cargo.toml index bcf625f..7a3748f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rsbuf" -version = "225.1.7" +version = "225.1.8" edition = "2021" authors = ["2004Scape"] description = "A RuneScape update info computer." diff --git a/package.json b/package.json index 874cc7c..108c9e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@2004scape/rsbuf", - "version": "225.1.7", + "version": "225.1.8", "description": "A RuneScape update info computer", "main": "dist/rsbuf.js", "types": "dist/rsbuf.d.ts",